【问题标题】:getting error: is not a function in postman收到错误:不是邮递员中的功能
【发布时间】:2021-03-08 17:05:28
【问题描述】:

我正在用 postman 编写基本 API 测试,我不知道为什么我收到这两个测试的错误消息,消息是相同的:res.every 不是函数,forEach 不是函数

pm.test("All supplier users have uuid", function () {
const res = pm.response.json();
pm.expect(res.every(uuidIsDefined)).to.be.true; 

});

pm.test("Every item has id an from ids[]", () => {
response = pm.response.json();
response.forEach(element => pm.expect(element.id).to.be.oneOf(ids));
});

【问题讨论】:

  • resresponse 不是数组。
  • 不,它们确实是一个 json 对象,知道如何对 json 对象做同样的事情吗?
  • 请添加您的回复

标签: javascript postman chai


【解决方案1】:

事实上,我的 json 对象中有一个内部数组,所以我必须先指向该数组。如果没有数组存在,则必须解析 json:

pm.test("Test name", function () {
   const resp = pm.response.json();
   pm.expect(resp.results.every((res) => {
       return res.uuid != undefined;
   })).to.be.true;
   

});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 2021-05-26
    • 2014-08-12
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多