gpt4 book ai didi

postman - 检查 Postman 测试用例中的空值 .not.eql() 或 .not.equal() 不起作用

转载 作者:行者123 更新时间:2023-12-04 16:43:23 26 4
gpt4 key购买 nike

我正在处理一个 API 项目并使用 Postman 来测试 API。我写了几个测试用例来检查 null 如下,

//user id is present
pm.test("user id is present", function() {
pm.expect(jsonData.data[0].userId).not.eql(null);
});

也试过 .not.equal()this 中所述回答。
//user id is present
pm.test("user id is present", function() {
pm.expect(jsonData.data[0].userId).not.equal(null);
});

但是,即使 userId 是 null,这一切都将通过.有没有想过在 Postman 测试用例中检查空值?

最佳答案

首先,打开控制台并运行流动的代码段来检查类型:

pm.test("user id is present", function() {
console.log(typeof jsonData.data[0].userId);
console.log(typeof jsonData.data[0]);
console.log(typeof jsonData);
}

如果您收到 undefinedjsonData.data[0].userId ,您需要更改测试以断言 nullundefined :
pm.test("user id is present", function() {
pm.expect(jsonData.data[0].userId).to.exist //check if it is not equal to undefined
pm.expect(jsonData.data[0].userId).to.not.be.null; //if it is not equal to null
}

关于postman - 检查 Postman 测试用例中的空值 .not.eql() 或 .not.equal() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54398327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com