ValeriaVG / tiny-jest

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

expect(testee).toMatchObject(reference) != expect(reference).toMatchObject(testee) #3

Closed GeorgGerber closed 2 years ago

GeorgGerber commented 2 years ago

scenario: expect(testee).toMatchObject(reference);

testee = {a:1,b:2,c:3} reference = {a:1,b:2} will not succeed

testee = {a:1,b:2} reference = {a:1,b:2,c:3} will succeed

Is this behaviour a bug or a feature? In my use case, I want to get "not successful" in both cases

ValeriaVG commented 2 years ago

This works as intended, toMatchObject is a loose comparison:

  const more = { a: 1, b: 2, c: 3 };
  const less = { a: 1, b: 2 };

  expect(more).toMatchObject(more);
  expect(less).toMatchObject(less);

  expect(more).toMatchObject(less);
  expect(less).not.toMatchObject(more);