无效的chai属性jsonschema



我正在使用mocha和chai进行API自动化。

我需要比较api的响应,并将其与chai jsonschema断言进行比较。

expect(response).to.be.jsonSchema(expectedResponse)

我得到以下错误,

Error: Invalid Chai property: jsonSchema
at Object.proxyGetter [as get] (node_moduleschailibchaiutilsproxify.js:78:17)
at _callee2$ (test/ServerEndPointsTest.js:70:21)
at tryCatch (node_modulesregenerator-runtimeruntime.js:63:40)
at Generator.invoke [as _invoke] (node_modulesregenerator-runtimeruntime.js:294:22)
at Generator.next (node_modulesregenerator-runtimeruntime.js:119:21)
at asyncGeneratorStep (node_modules@babelruntimehelpersasyncToGenerator.js:3:24)
at _next (node_modules@babelruntimehelpersasyncToGenerator.js:25:9)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

您还没有提到测试文件的导入,很可能这就是您犯错误的地方。

当你试图使用非内置的chai-json-schema插件时,chai库会抛出这些错误。

尝试如下方式更新导入:

const {expect} = require("chai").use(require('chai-json-schema'));

这将把chai插件所需的方法添加到expect对象中。

最新更新