Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman: test throws assertion error `expected null to deeply equal undefined`

I have an API response as follows:

[
    {
        "id": 1,
        "instance_id": 1400,
        "entity_uuid": 21,
        "field": null,
        "old_value": null,
        "new_value": null,
        "kind": "C",
        "updated_by": "binish",
        "updated_dt": "2017-12-28T13:19:22.000Z"
    }
]

I want to validate the value of old_value field in Postman and below is the code:

var data = pm.response.json(responseBody);
var oldValue = data.old_value;
var nullValue = null;

pm.test("Old Value is NULL", function(){
    pm.expect(nullValue).to.be.eql(oldValue);
});

The test throws an error:

"AssertionError: expected null to deeply equal undefined".

What am I doing wrong here?

like image 823
Sameem Avatar asked Feb 06 '26 02:02

Sameem


1 Answers

Could you use something like this to check that the old_valueproperty is null? This is using the built-in module Lodash to allow you to loop through the data in a cleaner way than a native JS for loop would do.

pm.test("Old Value is NULL", () => {
    _.each(pm.response.json(), (arrItem) => {
        console.log(arrItem)
        pm.expect(arrItem.old_value).to.be.null
    })
})

Postman

Using the data that you attached to the question, I extended this to add another object into the array. This was to show you that this test will check each object old_value property for the same null value, rather than limiting you to just looking at the first [0] object.

Postman

like image 119
Danny Dainton Avatar answered Feb 08 '26 16:02

Danny Dainton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!