Skip to content

Jest: Enforce use of new Error when testing thrown errors #327

@mcmire

Description

@mcmire

The toThrow matcher can take either a string or an Error object. If given a string, it tests that if there is a thrown error, the error message includes the given string; if given an Error, however, it tests that the thrown error message completely matches the given error message. In general, the complete message of an error should be tested, not just part of it, because error messages are part of user experience and it's important to verify that the user is seeing the right thing.

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