What is wrong with pm.expect

Hey @hasmukhpatel !

If you want to check if ‘data’ has all properties, you can iterate through each and perform assertion. Here is one way to achieve it:

let jsonData = pm.response.json();

console.log(jsonData.data);

pm.test("All keys present",()=>{
_.each(jsonData.data, (item)=>{
    
    pm.expect(item.hasOwnProperty('start_date')).to.be.true;
    pm.expect(item.hasOwnProperty('score')).to.be.true;
    pm.expect(item.hasOwnProperty('unit')).to.be.true;
    pm.expect(item.hasOwnProperty('status')).to.be.true;
})

})

Similarly you can even add assertions to check for presence of value.

Hope it helps,
Good luck!

1 Like