首页 > 解决方案 > 如何检查邮递员响应中是否没有特定数据?

问题描述

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

标签: javascripttestingpostman

解决方案


要确认 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;
});

查看测试脚本示例


推荐阅读