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?
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
})
})

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.

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