Skip to content

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

@DetachHead

Description

@DetachHead

Version

29.6.1

Steps to reproduce

import { JestAssertionError } from 'expect';

expect(() => {
 expect("1").toBeNumber();
}).toThrow(JestAssertionError);

Expected behavior

test should pass

Actual behavior

test fails

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

re-raising #13858 because it was closed and locked by the stale bot without a solution.

(please consider removing the stale bot, as it constantly closes valid issues that have not been resolved. just because nobody has commented on an issue in 30 days doesn't mean it's no longer an issue)

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
  Binaries:
    Node: 21.6.1 - C:\Program Files\nodejs\node.EXE     
    npm: 10.3.0 - C:\Program Files\nodejs\npm.CMD       
    pnpm: 7.27.0 - ~\AppData\Local\pnpm\pnpm.EXE        
  npmPackages:
    jest: ^29.6.1 => 29.6.1

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