[英]Postman Script if else condition for null values
如果你确定jsonData
是一个数组,你可以检查它的长度:
if (jsonData.length === 0) {
// ...
}
如果你不确定它是一个数组,你可以确保然后检查它的长度:
if (Array.isArray(jsonData) && jsonData.length === 0) {
// ...
}
Comparing it with null
will always result in false
, because the variable jsonData
does not hold the value null
, it holds an array, which is an object, and thus different from null
.
您可以设置以下条件,因为它不是null
它是一个empty array
pm.test("Cases here", function () {
var jsonData = pm.response.json();
if (!jsonData || !jsonData.length) { # see condition here
console.log('1');
postman.setNextRequest("Get Count");
}
else {
console.log('2');
postman.setNextRequest("Create");
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.