mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 20:52:08 +08:00
@ -7,7 +7,7 @@ describe('validateData', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('should throw an error if data is an array', () => {
|
test('should throw an error if data is an array', () => {
|
||||||
assert.throws(() => validateData([]), /Data must be an object. Found array./)
|
assert.throws(() => validateData([]), /Data must be an object. Found array/)
|
||||||
})
|
})
|
||||||
|
|
||||||
test("shouldn't throw an error", () => {
|
test("shouldn't throw an error", () => {
|
||||||
|
@ -17,8 +17,10 @@ module.exports = (obj) => {
|
|||||||
Object.keys(obj).forEach(validateKey)
|
Object.keys(obj).forEach(validateKey)
|
||||||
} else {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Data must be an object. Found ${Array.isArray(obj) ? 'array' : typeof obj}.` +
|
`Data must be an object. Found ${
|
||||||
'See https://github.com/typicode/json-server for example.'
|
Array.isArray(obj) ? 'array' : typeof obj
|
||||||
|
}
|
||||||
|
'See https://github.com/typicode/json-server for example.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user