Skip to content

Commit e371afd

Browse files
authored
Display type correctly for array if obj passed as an array (#1394)
* Display type correctly for array if obj passed as an array * Narrow the test case for `should throw an error if data is an array`
1 parent fa60189 commit e371afd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

__tests__/server/validate-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe('validateData', () => {
77
})
88

99
test('should throw an error if data is an array', () => {
10-
assert.throws(() => validateData([]), /must be an object/)
10+
assert.throws(() => validateData([]), /Data must be an object. Found array./)
1111
})
1212

1313
test("shouldn't throw an error", () => {

src/server/router/validate-data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = (obj) => {
1717
Object.keys(obj).forEach(validateKey)
1818
} else {
1919
throw new Error(
20-
`Data must be an object. Found ${typeof obj}.` +
20+
`Data must be an object. Found ${Array.isArray(obj) ? 'array' : typeof obj}.` +
2121
'See https://github.com/typicode/json-server for example.'
2222
)
2323
}

0 commit comments

Comments
 (0)