Postman Tests里怎么断言响应数据中的数组长度?

东方兴翰 阅读 4

我在用 Postman 写接口测试脚本,接口返回的是一个包含 users 数组的对象。我想断言这个数组长度是否等于 3,但一直报错说 tests[“xxx”] is not a function 或者 pm.expect 不生效。我试过用 pm.response.json() 拿数据,但不确定怎么正确写断言。

这是我的响应结构,前端代码里是这么处理的:

const res = await fetch('/api/users');
const data = await res.json();
console.log(data.users.length); // 正常输出 3

但在 Postman Tests 里写 pm.test(“users length”, () => { … }) 就不行,到底该怎么写才对?

我来解答 赞 0 收藏
二维码
手机扫码查看
暂无解答

暂无解答