You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 JSON
For 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 WORKSproperties: {a: {type: 'number'}}});}// properly fails because received value is not JSON
I 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).
The text was updated successfully, but these errors were encountered:
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:
For this to work, add
type: 'object'
at the root level of the schemaI 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).
The text was updated successfully, but these errors were encountered: