[Bug]: toThrow
and toStrictEqual
matchers compare only message
field of errors #13604
Closed as not planned
Closed as not planned
Description
opened on Nov 11, 2022
Version
29.3.1
Steps to reproduce
- Clone my repo https://github.com/tbossi/jest-bug-error-match
- Run
npm test
- The tests fail
Expected behavior
All tests should pass.
Specifically:
- Custom error objects with same
message
field value but different other fields values should not be equal. - In JavaScript you can
throw
custom objects (not extendingError
), therefore thetoThrow
matcher should compare the whole object and not only themessage
field (which could be missing).
Actual behavior
Error objects equality is only established by comparing the message
field.
Additional context
No response
Environment
System:
OS: Windows 10 10.0.22621
CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
Binaries:
Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
npmPackages:
jest: ^29.3.1 => 29.3.1
Activity