How to test if something is greater than certain number with POSTMAN

mavi picture mavi · Nov 20, 2017 · Viewed 24.1k times · Source

I'm trying to make a test in POSTMAN where the size has to be greater than 0 but I haven't been able to make the test correctly.

What I did was to make it fail when the size is smaller than 0.

Is there a function in postman to check if the size is greater than x number?

    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{
            //I will make the test fail if there is not data available on the response.
            pm.test("Response body is empty ", function () {
                pm.expect(pm.response.json().resources.length).to.equal(1);
            });

        }
        console.log(Boolean(jsonData.resources.length>1))
    }

});

Answer

anti_gone picture anti_gone · Apr 10, 2018
pm.expect(pm.response.json().resources.length).to.be.above(0);

See http://www.chaijs.com/api/bdd/