supermacro / neverthrow

Type-Safe Errors for JS & TypeScript
MIT License
4.03k stars 84 forks source link

Update to 8.1.0 breaks `toMatchObject` comparison #605

Open sna6mu opened 3 weeks ago

sna6mu commented 3 weeks ago

Using the following test

 it('Can compare objects', () => {
    expect(err({ important: 42, useless: 7 })).toMatchObject(err({ important: 42 }));
    expect(err({ important: 42, useless: 7 })).not.toMatchObject(err({ important: 43 }));
  });

was possible (and often times used for our code), but now breaks with 8.1.0 with

Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

- Err {
+ Object {
    "error": Object {
      "important": 42,
    },
  }

Any ideas why?

sna6mu commented 3 weeks ago

Interestingly, the test expect(err({ important: 42, useless: 7 })).toMatchObject(err({ important: 42, useless: 7 })); works! We also got green results when using vitest@2.1.3 instead of jest.

busywhistling commented 2 weeks ago

The issue is still there. A workaround in the meantime would be the following, and so on:

expect(relevantResult.isErr()).toBe(true);
expect(relevantResult._unsafeUnwrapErr()).toMatchObject({important: 42});