Skip to content

[Bug]: toThrow(JestAssertionError) crashes the test instead of passing #13858

@BalassaMarton

Description

@BalassaMarton

Version

29.4.1

Steps to reproduce

  1. Clone my repo at https://github.com/BalassaMarton/jest-matcher-test-repro
  2. yarn install
  3. yarn test

The project contains a custom matcher, and a test that tests this custom matcher:

        expect(() => {

            expect("1").toBeNumber();

        }).toThrow(JestAssertionError);

Expected behavior

All tests should pass

Actual behavior

Test fails (crashes) with below output:

expect(received).toThrow(expected)

    Expected constructor: JestAssertionError
    Received constructor: JestAssertionError

    Received message: "Expected received to be a number but found 1."

[call stack and other info trimmed]

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        2.015 s, estimated 3 s
Ran all test suites.

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
  Binaries:
    Node: 19.5.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 3.4.1 - C:\Program Files\nodejs\yarn.CMD
    npm: 9.3.1 - C:\Program Files\nodejs\npm.CMD

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions