Hey all!
I trying to check that an object returns either null or a dynamic string value but im struggling to find the right way to write the tests.
Below is part of the response thats being returned that i want to check.
"image": null,
"label_image": null,
"model_image": "https://m.media-amazon.com/images/I/41hZWA3Ax4L._SL500_.jpg",
"shipping": {
"prime": false,
"url": null
Now, the objects will return either a string value or null so i need a test that checks that, below is what i have so far:
pm.expect(responseJson.widget.data.offers[0].model_image === 'string' || responseJson.widget.data.offers[0].model_image === null).to.be.true
Issue is that the above fails when the object returns a string value, AssertionError: expected false to be true. So im not sure where to go from here.
Thanks!
Try to.be.oneOf
Chai Assertion Library - oneof method
Testing for null or “string” isn’t straight forward.
However, its been discussed on the forum before.
Hi,
I’m the following test to check my json response is structured correctly.
How can I check that the property ‘field_apply_url’ returns as either null or a string? I’m struggling to find a way how to do it.
const jsonData = pm.response.json();
pm.test("Apprenticeship details response is structured correctly", () => {
pm.expect(jsonData).to.be.an("object");
pm.expect(jsonData).to.have.property('nid').to.be.a('string');
pm.expect(jsonData).to.have.property('field_apply_url').to.be.a…
const response = pm.response.json();
pm.test("model_image = string or null", () => {
let model_image = response.model_image;
pm.expect(Object.prototype.toString.call(model_image)).to.be.oneOf(["[object String]","[object Null]"])
});
Mike Jones:
const response = pm.response.json();
pm.test("model_image = string or null", () => {
let model_image = response.model_image;
pm.expect(Object.prototype.toString.call(model_image)).to.be.oneOf(["[object String]","[object Null]"])
});
Thank you so much, I did read over that and tried ut
system
(system)
Closed
August 8, 2024, 2:25pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.