![](/img/trans.png)
[英]POSTman - Test with custom function throws an assertion error
[英]Practicing in Postman API testing and test failing because of an Assertion Error
我正在發帖請求在練習 api 上創建用戶,不幸的是,當我開始測試時,我繼續失敗,特別是“AssertionError:預期‘405’是一個數字”。 我不明白我哪里出錯了。
console.log(pm.response.json())
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
bodyData = pm.response.json()
console.log(bodyData)
pm.test("ID is created", () => {
pm.expect(bodyData.id).to.be.a("number");
})
我希望測試通過,因為它會在主體內獲取響應數據,特別是創建用戶時提供的 ID,因為這是一個數字,我構建我的測試以傳遞存在數字的斷言在響應主體的這一部分
有人回答了我的問題並給了我解決方案,他告訴我檢查 id 是否是字符串而不是數字,這解決了我的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.