Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest-circus] Tests failing with unhandled exception/rejections will wait for timeout #10530

Closed
timoxley opened this issue Sep 17, 2020 · 3 comments

Comments

@timoxley
Copy link

💥 Regression Report

Callback style tests that fail with an uncaughtException seem to wait until the timeout occurs before proceeding.
I assume it's waiting for a done that's never called. unhandledRejection does not wait.

This only happens when using jest-circus/runner (v26.4.2).

Consider the code below:

test('uncaught exception fails quickly', (done) => {
    setTimeout(() => {
        expect(true).toBe(false) // will trigger uncaught exception handler
        done()
    })
})

test('unhandled rejection fails quickly', async () => {
    const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))

    // intentionally unchained async
    wait().then(() => {
        expect(true).toBe(false) // will trigger unhandled rejection handler
    })

    await wait(100) // ensure still inside this test when unhandled rejection above happens
})

Default jasmine2 runner: 7ms + 2ms

 FAIL  test/Test.test.js
  ✕ uncaught exception fails quickly (7 ms)
  ✕ unhandled rejection fails quickly (2 ms)

  ● uncaught exception fails quickly

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      1 | test('uncaught exception fails quickly', (done) => {
      2 |     setTimeout(() => {
    > 3 |         expect(true).toBe(false)
        |                      ^
      4 |         done()
      5 |     })
      6 | })

      at Timeout._onTimeout (test/Test.test.js:3:22)

  ● unhandled rejection fails quickly

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      11 |     // intentionally unchained async
      12 |     wait().then(() => {
    > 13 |         expect(true).toBe(false) // unhandled rejection
         |                      ^
      14 |     })
      15 |
      16 |     await wait(100) // ensure still inside this test when unhandled rejection happens above

      at test/Test.test.js:13:22

Test Suites: 1 failed, 1 total
Tests:       2 failed, 2 total
Snapshots:   0 total
Time:        1.851 s, estimated 8 s
Ran all test suites matching /test\/Test.test.js/i.

jest-circus/runner: 5004ms + 105 ms

 FAIL  test/Test.test.js (7.058 s)
  ✕ uncaught exception fails quickly (5004 ms)
  ✕ unhandled rejection fails quickly (105 ms)

  ● uncaught exception fails quickly

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      1 | test('uncaught exception fails quickly', (done) => {
      2 |     setTimeout(() => {
    > 3 |         expect(true).toBe(false)
        |                      ^
      4 |         done()
      5 |     })
      6 | })

      at Timeout._onTimeout (test/Test.test.js:3:22)

  ● uncaught exception fails quickly

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

    > 1 | test('uncaught exception fails quickly', (done) => {
        | ^
      2 |     setTimeout(() => {
      3 |         expect(true).toBe(false)
      4 |         done()

      at Object.<anonymous> (test/Test.test.js:1:1)

  ● unhandled rejection fails quickly

    expect(received).toBe(expected) // Object.is equality

    Expected: false
    Received: true

      11 |     // intentionally unchained async
      12 |     wait().then(() => {
    > 13 |         expect(true).toBe(false) // unhandled rejection
         |                      ^
      14 |     })
      15 |
      16 |     await wait(100) // ensure still inside this test when unhandled rejection happens above

      at test/Test.test.js:13:22

Test Suites: 1 failed, 1 total
Tests:       2 failed, 2 total
Snapshots:   0 total
Time:        7.116 s
Ran all test suites matching /test\/Test.test.js/i.

Expected Behaviour

Unhandled rejections/exceptions should behave the same where possible. Ideally neither waits around for the timeout.

Run npx envinfo --preset jest

  System:
    OS: macOS 10.15.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.7.0 - /usr/local/bin/node
    npm: 6.14.8 - /usr/local/bin/npm
  npmPackages:
    jest: ^26.4.2 => 26.4.2

jest-circus": "^26.4.2"
@github-actions
Copy link

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

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions
Copy link

github-actions bot commented May 1, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant