-
Notifications
You must be signed in to change notification settings - Fork 14
Description
If the schema to be matched against doesn't contain type: 'object' at the root level, then if the received value is not JSON (e.g. a number), it won't fail.
Example:
it('should verify it has received an object'), () => {
expect(1).toMatchSchema({
properties: {
a: { type: 'number' }
}
});
}
// should fail because received value is not JSONFor this to work, add type: 'object' at the root level of the schema
it('should verify it has received an object'), () => {
expect(1).toMatchSchema({
type: 'object', // THIS WORKS
properties: {
a: { type: 'number' }
}
});
}
// properly fails because received value is not JSONI know that the type property at the root level is part of the JSON Schema specification, and is optional, but seeing that a JSON object is always an object, and not a number or string (although it can contain a property that is a number or string), the type property at the root level should not be present in order to validate that a JSON object is being passed in.
Proposal: The first example above (without the type property at the root level) should cause the test to fail, saying it's received a value that's not JSON (or object).