object to contain jest code example
Example 1: jest test array of objects
const users = [{id: 1, name: 'Hugo'}, {id: 2, name: 'Francesco'}];
test('we should have ids 1 and 2', () => {
expect(users).toEqual(
expect.arrayContaining([
expect.objectContaining({id: 1}),
expect.objectContaining({id: 2})
])
);
});
Example 2: jest expect not contain
expect('some string').toEqual(expect.not.stringContaining('something else'))