javascript - 如何检查邮递员响应中是否没有特定数据?
问题描述
我正在发送一个在邮递员中产生问题的请求。我得到一个 json 数据作为响应,我需要检查该数据是否不包含指定的元素。我如何在测试中做到这一点?
解决方案
要确认 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;
});
查看测试脚本示例。
推荐阅读
- amazon-web-services - MacOS 上 StarCluster 安装在哪里
- image - 从左视图图像和视差图构造右视图图像
- postgresql - 只允许特定用户访问(Postgres)
- excel - 如何计算文件中找到的字符串实例
- c# - 有没有绕过类的静态构造函数的api
- java - Hibernate 5 + Spring + JDBC 瘦客户端 UCP 接口对类加载器不可见
- java - java utf8编码输出流不起作用
- rx-java - 使用混合的 Maybe 和 Single 时如何避免嵌套订阅
- bash - 如何在 git 中取消暂存已删除的文件
- design-patterns - 设计 - 在 SQL 中存储可执行代码的替代方案