Answers for "jest match object"

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 match object properties

describe('location', () => {
  it('should return location object', () => {
    expect( /* Some object value...*/ )
      .toEqual(expect.objectContaining({
        locationId: expect.any(Number),
        geo: expect.any(Array),
        isFetching: expect.any(Boolean)
      }))
  })
})
Posted by: Guest on May-04-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language