Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negation swallows missing schema errors #22

Closed
tad-lispy opened this issue Mar 29, 2016 · 2 comments
Closed

Negation swallows missing schema errors #22

tad-lispy opened this issue Mar 29, 2016 · 2 comments

Comments

@tad-lispy
Copy link

Consider this:

const schema = {
  anyOf: [
    {
      "enum": 'some value'
    },
    {
      $ref: 'invalid external schema reference'
    }
  ]
};

expect('invalid value').not.to.be.jsonSchema(schema);
expect('some value').not.to.be.jsonSchema(schema);

Expected behaviour:

Test fails with missing schema error.

What happens instead:

The test will pass no matter what value is checked against schema.

@JrSchild
Copy link
Member

I did some digging, turned out to be very simpel. When you define an enum it should always be an array. Therefore whatever you throw at it will never pass in this example. Try setting it to an array and it will work as expected.

http://spacetelescope.github.io/understanding-json-schema/reference/generic.html#enumerated-values

The enum keyword is used to restrict a value to a fixed set of values. It must be an array with at least one element, where each element is unique.

@tad-lispy
Copy link
Author

Hej, @JrSchild. I'm happy that you took over maintenance of this valuable project. Also thanks for your response. You are right, the error was on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants