How to test if something is greater than certain number with POSTMAN
pm.expect(pm.response.json().resources.length).to.be.above(0);
See http://www.chaijs.com/api/bdd/
Postman uses an extended implementation of the chai library. You can check out the source code here: https://github.com/postmanlabs/chai-postman
So logically the test only fails when you throw an error and the test catches it. Else it simply passes. So the expect calls actually throw an error which makes the test fail. If you just return anything or maybe return nothing, even then the test would pass.
Think in terms of a simple try and catch block. So, to solve your problem instantly you can just throw an error and your test would fail.
You can modify your code like so:
pm.test("Step 7/ Getting the resources and availabilites list " , function(){
pm.expect(pm.response.code).to.be.oneOf([200]);
if(pm.response.code === 200){
var jsonData = JSON.parse(responseBody);
var sizeOK= 1;
if(jsonData.resources.length>0){
} else {
pm.test("Response body is empty ", function () {
throw new Error("Empty response body"); // Will make the test fail.
});
}
console.log(Boolean(jsonData.resources.length>1))
}
});
Also, you can additionally use simple javascript to test the length / size easily like so (just an eg.):
pm.test("Step 7/ Getting the resources and availabilites list " , function(){
pm.expect(pm.response.code).to.be.oneOf([200]);
if(pm.response.code === 200){
var jsonData = JSON.parse(responseBody);
var sizeOK= 1;
if(jsonData.resources.length>0){
} else {
pm.test("Response body is empty ", function () {
if(jsonData.length < 3) {
throw new Error("Expected length to be greater than 3");
}
});
}
console.log(Boolean(jsonData.resources.length>1))
}
});