Answers for "jest check array of string"

3

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
1

jest check array of string

const fruits = ['apple', 'cat'];

test('should have array of string', () => {
  expect(fruits).toEqual(
    expect.arrayContaining([expect.any(String)])
  );
});
Posted by: Guest on April-06-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language