Hello everyone, I have tried and tried and tried but it just wont work, am I missing something?
My test simplified:
var responseBody = pm.response.json();
var price = responseBody.price;
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("price exists", function () {
console.log("checking if price exists");
if (pm.expect(price).not.eq(undefined)) {
console.log("price exists");
}
else {
console.log("price does not exists");
}
});
Response:
{
"productId": "DP1234"
}
I will expect âprice does not existsâ to be logged, but nothing is logged except for âchecking if price existsâ. What am I doing wrong??
For the record, i have tried:
pm.expect(price).to.be.not.undefined;
pm.expect(price).not.to.be.undefined;
pm.expect(price).to.be.a('number');
I have also tried setting price to 0 and assert if not zero:
var price = responseBody.price;
They all did the same thing. It almost seems like it is ignoring all the code after the assertion. I have run out of ideasâŚ
Thanks in advance for any feedback!