mfol
mfol

Reputation: 31

Insomnia returning Error: Invalid Chai property: jsonSchema

I’m trying to validate a JSON response in Insomnia against a predefined schema using an after-response script. Here’s my script:

var statisticsSchema = {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Generated schema for Root",
  "type": "object",
  "properties": {
    "message": {
      "type": "string"
    }
  },
  "required": [
    "message"
  ]
}

insomnia.test('Response corresponds to json schema', () => {
  const jsonBody = insomnia.response.json();
  insomnia.expect(jsonBody).to.be.jsonSchema(statisticsSchema);
});

However, when I run this, I get the following error:

Error: Invalid Chai property: jsonSchema

enter image description here

It seems like the jsonSchema method is not recognized by the built-in assertion library in Insomnia, although I found the PR that should have implemented it https://github.com/Kong/insomnia/pull/6532

Am I using it the wrong way? I haven't found any more information in the Insomnia official documentation.

Upvotes: 0

Views: 25

Answers (1)

Jeremy Fiel
Jeremy Fiel

Reputation: 3219

the correct assertion is to.have.jsonSchema

insomnia.test('Response corresponds to json schema', () => {
  const jsonBody = insomnia.response.json();
  insomnia.expect(jsonBody).to.have.jsonSchema(statisticsSchema);
});

src: https://github.com/Kong/insomnia/pull/7481/files

Upvotes: 0

Related Questions