question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

beforeAll() executed in parallel with test case in case of timeout

See original GitHub issue

🐛 Bug Report

Test case is executed even if beforeAll did not finish.

To Reproduce

This test file:

beforeAll(async () => new Promise((resolve, reject) => {
  // Never resolves
}));

test('test case', async () => {
  console.log('should never be executed');
});

Displays this:

% npx jest t.spec.js
 FAIL  ./t.spec.js (5.415s)
  ✕ test case (8ms)

  ● test case

    Timeout - Async callback was not invoked within the 5000ms timeout specified by jes
t.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout 
specified by jest.setTimeout.

      at mapper (node_modules/jest-jasmine2/build/queueRunner.js:25:45)

  console.log t.spec.js:6
    should never be executed

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        5.436s, estimated 6s
Ran all test suites matching /t.spec.js/i.

Expected behavior

Test case code should never be executed because beforeAll() did not finish. The error message should be at the beforeAll level and not at the test case level. This is very confusing as you may think that the test case itself failed when in reality it has nothing to do with the test case.

Link to repl or repo (highly encouraged)

https://repl.it/repls/KindlyAutomaticLocation

envinfo

% npx envinfo --preset jest
npx: installed 1 in 0.645s

  System:
    OS: Linux 5.3 Manjaro Linux
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 13.7.0 - /usr/bin/node
    Yarn: 1.21.1 - /usr/bin/yarn
    npm: 6.13.6 - /usr/bin/npm
  npmPackages:
    jest: ^24.9.0 => 24.9.0 

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:39
  • Comments:33 (9 by maintainers)

github_iconTop GitHub Comments

14reactions
wanton7commented, Jan 18, 2021

Our company lost 4 man-days of development because of this bug. Please fix this so others don’t suffer the same fate. Return proper error for this and don’t run test if beforeAll etc timeouts. So they know that they need to put bigger timeout as second argument for beforeAll and afterAll etc.

14reactions
mateuspireslcommented, Jul 18, 2020

I’m facing this issue. Agree with @albert-schilling. There is no point in testing being run before preparation (beforeAll and beforeEach) is complete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - jest doesn't wait beforeAll resolution to start tests
I found the solution. After trying almost anything, I didn't realize jest had a timeout setup which defaults at 5 seconds.
Read more >
Junit 5 timeouts - Fail if test not executed within time
Example 2 : If @Timeout declared at @BeforeAll and exceeds timeout, execution will be aborted, skips the rest of test cases. public ...
Read more >
Unit testing fundamentals - Visual Studio (Windows)
Learn how Visual Studio Test Explorer provides a flexible and efficient way to run your unit tests and view their results.
Read more >
Playwright Test - CukeTest
Playwright Test provides a test function to declare tests and expect function to write ... Declares a beforeAll hook that is executed once...
Read more >
Mocha documentation — DevDocs
WARNING: Exclusive tests are incompatible with parallel mode. The exclusivity feature allows you to run only the specified suite or test-case by appending...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found