Hi, I just want to make sure that this is correctly testing that An Object and an Object within an array is present.
Example api:
{
"items": [
{
"oID": "0000001211",
"oInvoiceNo": "1234567",
"OrderBlocks": [
{
"olLine": 1,
"olProductCode": "001"
}
]
}
]
}
Example test:
pm.test("Order Details are Present", () => {
pm.response.to.have.jsonBody("oID");
pm.response.to.have.jsonBody("oInvoiceNo");
pm.response.to.have.jsonBody("OrderBlocks[0].olLine");
pm.response.to.have.jsonBody("OrderBlocks[0].olProductCode");
});
It’s returning as a Pass, but I’ve been experimenting with syntax all day with loads of different tests(I can’t remember .js and pm.* so I just refactor constantly until it works), and I’m sure I had one earlier that brought back a False Pass, just wanted to make sure that this is a correct way for checking that the correct properties, and properties within arrays are present in a response.
I also don’t completely understand why this seems to work, shouldn’t “oID” also require me to have an array like (“items[0].oID”) ? Yet when I try this, it fails to find oID.
Was trying this initially and it failed, so the above is my new “fix”:
pm.test("Order Details are Present", () => {
pm.response.to.have.jsonBody("items.OrderBlocks.olLine");
});
Any help/advice on testing this kind of stuff correctly is really appreciated, thanks!



