Skip to content

[Bug]: toThrow and toStrictEqual matchers compare only message field of errors #13604

Closed as not planned
@tbossi

Description

Version

29.3.1

Steps to reproduce

  1. Clone my repo https://github.com/tbossi/jest-bug-error-match
  2. Run npm test
  3. The tests fail

Expected behavior

All tests should pass.

Specifically:

  1. Custom error objects with same message field value but different other fields values should not be equal.
  2. In JavaScript you can throw custom objects (not extending Error), therefore the toThrow matcher should compare the whole object and not only the message 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions