jest: [Bug]: `toThrow(JestAssertionError)` crashes the test instead of passing

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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 34

Most upvoted comments

not stale

not stale

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.