I'm running into an issue where I have a response that contains an array of objects, the array isn't always in the same order based on the response, but I need to verify that at least 1 of the objects in the array of objects contains a specific value (or key/value pair).
For example, the JSON looks like this:
{
data: [
{
foo: 'Name 1',
bar: '2022-06-07T00:00:00',
},
{
foo: 'Name 2',
bar: '2022-06-07T00:00:00',
},
{
foo: 'Name 3',
bar: '2022-06-07T00:00:00',
}
}
I would use something like expect(responseBody.data).toContainEqual({foo: "Name 2"}), but that doesn't work. Would something like toHaveProperty work better? (Still not sure I understand the difference between toEqual, toBe and toContainEqual etc., as they feel very similar.
I suppose I need to add something, the object itself I'm checking may contain random data (like dates/timestamps/etc.), so I won't know specifically all data of the object.