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:
- Created 4 years ago
- Reactions:39
- Comments:33 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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
beforeAlletc timeouts. So they know that they need to put bigger timeout as second argument forbeforeAllandafterAlletc.I’m facing this issue. Agree with @albert-schilling. There is no point in testing being run before preparation (
beforeAllandbeforeEach) is complete.