【问题标题】:How do I check that there is no specific data in postman response?如何检查邮递员响应中是否没有特定数据?
【发布时间】:2020-12-15 07:58:34
【问题描述】:

我正在发送一个在邮递员中产生问题的请求。我得到一个 json 数据作为响应,我需要检查该数据是否不包含指定的元素。如何在测试中做到这一点?

【问题讨论】:

  • 你试过什么?你读过文档吗?
  • 什么是响应正文以及您不希望它包含的值是什么?没有这些基本信息,没有人能给你一个具体的答案。

标签: javascript testing postman


【解决方案1】:

要确认 json 响应中缺少某个值,您可以使用 pm.expect(jsonResponse.value).to.be.undefined

这是完整的例子:

pm.test("valueThatShouldNotBePresent is missing from the json response", function () {
    var jsonData = pm.response.json();
    pm.expect(jsonData.valueThatShouldNotBePresent).to.be.undefined;
});

查看Test Script Examples

【讨论】:

    【解决方案2】:

    我们还可以执行以下操作:

      const jsonData = pm.response.json()
        pm.test('Key abc is absent', () => {
            pm.expect(jsonData).to.not.have.any.keys('abc')
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-24
      • 2022-06-21
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多