Answers for "expect array of objects properties jest"

5

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})
    ])
  );
});
Posted by: Guest on June-19-2020
3

jest array contain object with prop

expect(state).toEqual(          // 1
  expect.arrayContaining([      // 2
    expect.objectContaining({   // 3
      type: 'END'               // 4
    })
  ])
)
Posted by: Guest on June-10-2021

Code answers related to "expect array of objects properties jest"

Code answers related to "Javascript"

Browse Popular Code Answers by Language