【发布时间】:2021-09-27 17:11:04
【问题描述】:
我正在使用 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)
【问题讨论】:
-
你使用哪个 chai 插件?
-
我的 package.json 中的 Chai 插件 "chai": "^4.3.4", "chai-json-schema": "^1.5.1",
-
你是如何使用
chai-json-schema的?展示最小的、可重现的代码示例 -
response = res.body expect(response).to.be.jsonSchema(expectedResponse.GetCCAccounts.with) ExpectedResponse.js var expectedResponse = { GetCCAccounts: { "with":{ "response": { "code": '0303', "desc": '无效的会话令牌。' }, "httpCode": 400 }
标签: mocha.js chai web-api-testing