This thread is trying to answer question "How can I assert if an array of objects contains a specific object in Jest?"
Hi, I suggest to use chai assertion library... there you have pretty cool stuff which help you to check the array in different ways.. Have a look here -> https://medium.com/@mati-qa/playwright-chai-thats-all-what-you-need-3628b9293f60 And here is the library -> https://www.chaijs.com/api/bdd/#method_members
Example from here https://playwright.dev/docs/next/api/class-genericassertions#generic-assertions-to-equal
Just try to use expect(array).toEqual(expect.arrayContaining(value))
list: [1, 2, 3],
obj: { prop: 'Hello world!', another: 'some other value' },
extra: 'extra',
}).toEqual(expect.objectContaining({
list: expect.arrayContaining([2, 3]),
obj: expect.objectContaining({ prop: expect.stringContaining('Hello') }),
}));```
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].