Skip to content

[Docs]: toThrow fails if error object contains a cause property #15072

Closed as not planned
@kirkwaiblinger

Description

@kirkwaiblinger

Page(s)

https://jestjs.io/docs/expect#tothrowerror

Description

When attempting to use the toThrow() method to validate an exact error message, I expected the following code to pass, according to the docs.

expect((async () => { throw new Error('message', { cause: new Error('cause') }); })()).rejects.toThrow(new Error('message'))

However, it fails with error

expect(received).rejects.toThrow(expected)

- Expected message            - 1
+ Received message and cause  + 8

That's reasonable behavior, but it should be documented as such.

Metadata

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