I'm working on the API automation using mocha and chai.
I need to compare the response of the api and compare it with chai jsonschema assertion.
expect(response).to.be.jsonSchema(expectedResponse)
I get the following error,
Error: Invalid Chai property: jsonSchema
at Object.proxyGetter [as get] (node_modules\chai\lib\chai\utils\proxify.js:78:17)
at _callee2$ (test\/ServerEndPointsTest.js:70:21)
at tryCatch (node_modules\regenerator-runtime\runtime.js:63:40)
at Generator.invoke [as _invoke] (node_modules\regenerator-runtime\runtime.js:294:22)
at Generator.next (node_modules\regenerator-runtime\runtime.js:119:21)
at asyncGeneratorStep (node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)
at _next (node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
You have not mentioned the imports of your test file and most likely that is the place where you are making a mistake.
These sorts of errors are thrown by the chai library when you try to use something which is not in-built in your case the chai-json-schema plugin.
Try to update your imports as below:
const {expect} = require("chai").use(require('chai-json-schema'));
This will add the required methods of the chai plugin to your expect object.