Answers for "is an array in jest check"

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
0

jest check array of objects

test('id should match', () => {
  const obj = {
    id: '111',
    productName: 'Jest Handbook',
    url: 'https://jesthandbook.com'
  };
  expect(obj.id).toEqual('111');
});
Posted by: Guest on October-28-2020

Code answers related to "is an array in jest check"

Code answers related to "Javascript"

Browse Popular Code Answers by Language