我正在使用mocha和chai进行API自动化。
我需要比较api的响应,并将其与chai jsonschema断言进行比较。
expect(response).to.be.jsonSchema(expectedResponse)我得到以下错误,
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)发布于 2021-10-07 05:45:01
您没有提到测试文件的导入,而这很可能是您犯了错误的地方。
当您尝试使用chai-json-schema插件中未内置的内容时,chai库会抛出此类错误。
尝试更新导入,如下所示:
const {expect} = require("chai").use(require('chai-json-schema'));这会将chai插件所需的方法添加到expect对象中。
https://stackoverflow.com/questions/69350684
复制相似问题