How to check if an object does not exist in Response?

I want to verify that a particular error message is not displayed. I am trying assert that that property should not exist. But the test is passing in both the Condition.

Here is what I am doing:

var response = pm.response.json();
var property = (response.validationResponse.validationResponsesMap["individual.isUSPerson"]);

pm.test("Verify error message is not displayed for isUS person Null", function () {
     pm.expect(response).not.have.property('property');
});

This test is getting Passed if property exist and if it does not exist.

Can someone please suggest?

Welcome to the community :relaxed:Could you add an example, what value will property variable has

Hello there
You can use something like that, but as @praveendvd said, can you provide us an example

pm.test("UB", function(){
    
    pm.expect(pm.response.text()).to.include(pm.variables.replaceIn('{{Pnamestamp}}'));
    
});

Here is the part of Response:
“validationResponsesMap”: {

        "individual.isUSPerson": [

            {

                "errorMessage": "Missing value for required field: individual.isUSPerson",

                "ruleType": "REQUIRED",

                "fieldValue": "",

                "sequence": 0,

                "id": "",

                "shortCode": ""

            }

        ]

    },

In one scenario, I need to check that object “(response.validationResponse.validationResponsesMap[“individual.isUSPerson”])” does not exist.

let b =

{

    "validationResponsesMap": {

        "individual.isUSPerson": [

            {

                "errorMessage": "Missing value for required field: individual.isUSPerson",

                "ruleType": "REQUIRED",

                "fieldValue": "",

                "sequence": 0,

                "id": "",

                "shortCode": ""

            }

        ]

    }

}

pm.expect(b.validationResponsesMap).to.not.have.property("individual.isUSPerson");
2 Likes

Postman issues chai expect , so what ever chai expect api supports , postman supports the same