Insomnia 返回错误:无效的 Chai 属性:jsonSchema

问题描述 投票:0回答:1

我正在尝试使用响应后脚本根据预定义模式验证 Insomnia 中的 JSON 响应。这是我的脚本:

var statisticsSchema = {
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Generated schema for Root",
  "type": "object",
  "properties": {
    "message": {
      "type": "string"
    }
  },
  "required": [
    "message"
  ]
}

insomnia.test('Response corresponds to json schema', () => {
  const jsonBody = insomnia.response.json();
  insomnia.expect(jsonBody).to.be.jsonSchema(statisticsSchema);
});

但是,当我运行此程序时,出现以下错误:

Error: Invalid Chai property: jsonSchema

enter image description here

Insomnia 中的内置断言库似乎无法识别

jsonSchema
方法,尽管我找到了应该实现它的 PR https://github.com/Kong/insomnia/pull/6532

我使用方法错误吗?我在 Insomnia 官方文档中没有找到更多信息。

json jsonschema chai insomnia
1个回答
0
投票

正确的说法是

to.have.jsonSchema

insomnia.test('Response corresponds to json schema', () => {
  const jsonBody = insomnia.response.json();
  insomnia.expect(jsonBody).to.have.jsonSchema(statisticsSchema);
});

src:https://github.com/Kong/insomnia/pull/7481/files

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.