“Jest Test Array of Objects” Kode Jawaban

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})
    ])
  );
});
CharllierJr

Jest Check Array of String

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

test('should have array of string', () => {
  expect(fruits).toEqual(
    expect.arrayContaining([expect.any(String)])
  );
});
Obedient Oyster

Jest check array objek

test('id should match', () => {
  const obj = {
    id: '111',
    productName: 'Jest Handbook',
    url: 'https://jesthandbook.com'
  };
  expect(obj.id).toEqual('111');
});
Thoughtful Trout

Jawaban yang mirip dengan “Jest Test Array of Objects”

Pertanyaan yang mirip dengan “Jest Test Array of Objects”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya