Jest should avoid printing the individual tests if beforeAll fails
See original GitHub issue🐛 Bug Report
When beforeAll fails, none of the other tests actually execute, but they all fail with the same reason, and they all print the same error.
Jest should avoid printing the individual tests if beforeAll fails. Right now the implementation just checks if there is an error and if yes, print it and fail the test without actually executing it.
Note that @SimenB asked me to create this https://github.com/facebook/jest/issues/6695#issuecomment-619405847.
To Reproduce
Run a beforeAll() that fails where a couple of tests are executed after. This is the failure received (with the supplied repro below):
FAIL src/test.unit.test.js
test that a 3rd party API remains consistent
✕ API function 1
✕ API function 2
✕ API function 3
● test that a 3rd party API remains consistent › API function 1
expect(received).toBe(expected) // Object.is equality
Expected: "successful"
Received: "login"
1 | describe('test that a 3rd party API remains consistent', () => {
> 2 | beforeAll(() => expect('login').toBe('successful')); // this will fail
| ^
3 | test('API function 1', () => expect(1).toBe(1)); // each...
4 | test('API function 2', () => expect(2).toBe(2)); // ...of these...
5 | test('API function 3', () => expect(3).toBe(3)); // ...will fail too
at src/test.unit.test.js:2:35
● test that a 3rd party API remains consistent › API function 2
expect(received).toBe(expected) // Object.is equality
Expected: "successful"
Received: "login"
1 | describe('test that a 3rd party API remains consistent', () => {
> 2 | beforeAll(() => expect('login').toBe('successful')); // this will fail
| ^
3 | test('API function 1', () => expect(1).toBe(1)); // each...
4 | test('API function 2', () => expect(2).toBe(2)); // ...of these...
5 | test('API function 3', () => expect(3).toBe(3)); // ...will fail too
at src/test.unit.test.js:2:35
● test that a 3rd party API remains consistent › API function 3
expect(received).toBe(expected) // Object.is equality
Expected: "successful"
Received: "login"
1 | describe('test that a 3rd party API remains consistent', () => {
> 2 | beforeAll(() => expect('login').toBe('successful')); // this will fail
| ^
3 | test('API function 1', () => expect(1).toBe(1)); // each...
4 | test('API function 2', () => expect(2).toBe(2)); // ...of these...
5 | test('API function 3', () => expect(3).toBe(3)); // ...will fail too
at src/test.unit.test.js:2:35
Test Suites: 1 failed, 1 total
Tests: 3 failed, 3 total
Snapshots: 0 total
Time: 1.037s
Expected behavior
Jest should avoid printing the individual tests if beforeAll fails. It is highly confusing for users.
Link to repl or repo (highly encouraged)
describe('test that a 3rd party API remains consistent', () => {
beforeAll(() => expect('login').toBe('successful')); // this will fail
test('API function 1', () => expect(1).toBe(1)); // each...
test('API function 2', () => expect(2).toBe(2)); // ...of these...
test('API function 3', () => expect(3).toBe(3)); // ...will be reported as failed too
});
envinfo
System:
OS: Linux 4.15 Ubuntu 18.04.4 LTS (Bionic Beaver)
CPU: (4) x64 Intel(R) Xeon(R) Gold 6132 CPU @ 2.60GHz
Binaries:
Node: 12.15.0 - ~/.config/nvm/12.15.0/bin/node
npm: 6.13.4 - ~/.config/nvm/12.15.0/bin/npm
npmPackages:
jest: 25.1.0 => 25.1.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Setup and Teardown - Jest
If you have a test that often fails when it's run as part of a larger suite, but doesn't fail when you run...
Read more >Async beforeAll() does not finish before beforeEach() is called
The short answer is that Jest does wait for an async beforeAll() callback to finish before proceeding to beforeEach() . This means that...
Read more >Mocha - the fun, simple, flexible JavaScript test framework
Mocha is a feature-rich JavaScript test framework running on Node.js and in the ... If you use callback-based async tests, Mocha will throw...
Read more >Ginkgo test suite - GitHub Pages
RegisterFailHandler(Fail) is the single line of glue code connecting Ginkgo to Gomega. If we were to avoid dot-imports this would read as gomega....
Read more >Test runner Addon | Storybook: Frontend workshop for UI ...
The Storybook test runner uses Jest as a runner, and Playwright as a testing ... If there are any failures, the test runner...
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 FreeTop 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
Top GitHub Comments
@itaizelther thank you 🙏
@thernstig I have no write permissions to the existing PR, so I have created a new one: #13273 It is done, you may review it