首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无效的chai属性jsonschema

无效的chai属性jsonschema
EN

Stack Overflow用户
提问于 2021-09-27 17:11:04
回答 1查看 208关注 0票数 0

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

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

代码语言:javascript
复制
expect(response).to.be.jsonSchema(expectedResponse)

我得到以下错误,

代码语言:javascript
复制
 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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-07 05:45:01

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

当您尝试使用chai-json-schema插件中未内置的内容时,chai库会抛出此类错误。

尝试更新导入,如下所示:

代码语言:javascript
复制
const {expect} = require("chai").use(require('chai-json-schema'));

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69350684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档