I have an API whose response looks like this (notice that it is objects without name in array):
{
offers: [
{
sticker: null,
},
{
sticker: null,
score: "67",
},
{
sticker: null,
},
{
sticker: null,
},
{
sticker: null,
score: "70",
}
]
}
How to check if the property score exists in this API response? I tried using
expect(resp.body.offers.some((offer: any) => offer.score !== undefined && typeof offer.score === "string")).to.be.true;
and many other ideas I had but nothing works. It will always throw error expected false to be true.
Your assertion is actually passing (according to the code you posted), so it looks like the
responseis the offers arrayCypress lodash is really useful for parsing object lists, here's a few examples: