Replies: 2 comments
-
It requires additional chai plugin support, will take a look into it. Probably you could try ajv for now: // or ESM/TypeScript import
import Ajv from "ajv"
// Node.js require:
const Ajv = require("ajv")
const ajv = new Ajv() // options can be passed, e.g. {allErrors: true}
const schema = {
type: "object",
properties: {
foo: {type: "integer"},
bar: {type: "string"},
},
required: ["foo"],
additionalProperties: false,
}
const data = {
foo: 1,
bar: "abc",
}
const validate = ajv.compile(schema)
const valid = validate(data)
// insomnia.expect |
Beta Was this translation helpful? Give feedback.
-
This is indeed a good workaround. I am however a bit sad about the fact that it doesn't also support the avj-formats library to make some more defined checks, so we have to use patterns and $ref (for clean code if we reuse it.) I would recommend keeping it a bit open to see the update of the chai issue in insomnia and if there will be any fix necessary Edit: Also in the tests zone, at the error we still see Actual undefined and expected undefined, so we have to check the response body in regards with what it was wrong. We are giving the path where it failed. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have started to work into Insomnia and one of the tests I like to make and maintain are the schema validation because it saves a lot of code and time. I have checked the topics and it seems like it has been added somewhat a bit over an year ago so I made a small schema test... For some reason on my side Schema validation doesn't work at all, receiving
Check JSON Schema over response | error: Error: Invalid Chai property: jsonSchema | ACTUAL: undefined | EXPECTED: undefined
Is there a known issue to it or is there something I did wrong?
Beta Was this translation helpful? Give feedback.
All reactions