ValeriaVG / tiny-jest

Minimalistic zero dependency Jest-like test library to run tests in browser, nodejs or deno
16 stars 1 forks source link

fix: expect toMatchObject should properly handle arrays #4

Closed ValeriaVG closed 3 years ago

ValeriaVG commented 3 years ago

The following tests are now passing:

it("toMatchObject/arrays", () => {
  expect([]).toMatchObject([]);
  expect([]).not.toMatchObject({});
  expect([1, 2, 3]).toMatchObject([1, 2]);
  expect([2, 3]).not.toMatchObject([1, 2, 3]);
  expect([{ id: 1, name: "1" }, { id: 2, name: "2" }, { id: 3 }]).toMatchObject(
    [{ id: 1 }, { id: 2 }, { id: 3 }]
  );
  expect([{ id: 1 }, { id: 2 }, { id: 3 }]).not.toMatchObject([
    { id: 1, name: "1" },
    { id: 2, name: "2" },
    { id: 3 },
  ]);
  expect({ a: [1, 2, 3] }).toMatchObject({ a: [1, 2, 3] });
  expect({ a: [1, 2] }).not.toMatchObject({ a: [1, 2, 3] });
});