jest-circus beforeAll hook behaviour on failure
See original GitHub issue🐛 Bug Report
When you have a failing beforeAll
hook, all remaining beforeAll
hooks will still run. Contrast that to beforeEach
which after failing will skip the rest of the beforeEach
hooks and skip the test.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I think after the first beforeAll failure, every other beforeAll hook and child test should be skipped / failed.
Link to repl or repo (highly encouraged)
import wrap from 'jest-snapshot-serializer-raw';
import {runTest} from 'jest-circus/src/__mocks__/testUtils';
test('a failing beforeAll will not skip other beforeAll hooks', () => {
const {stdout} = runTest(`
describe('test suite beforeAll', () => {
beforeAll(() => {
console.log('beforeAll 1 runs')
throw new Error('beforeAll 1');
});
beforeAll(() => {
console.log('beforeAll 2 runs')
throw new Error('beforeAll 2');
});
test('should not run', () => {
console.log('the test ran')
});
});
`);
expect(wrap(stdout)).toMatchSnapshot();
});
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`a failing beforeAll will not skip other beforeAll hooks 1`] = `
Object {
Symbol(jest-snapshot-serializer-raw): "start_describe_definition: test suite beforeAll
add_hook: beforeAll
add_hook: beforeAll
add_test: should not run
finish_describe_definition: test suite beforeAll
run_start
run_describe_start: ROOT_DESCRIBE_BLOCK
run_describe_start: test suite beforeAll
hook_start: beforeAll
beforeAll 1 runs
hook_failure: beforeAll
hook_start: beforeAll
beforeAll 2 runs
hook_failure: beforeAll
test_start: should not run
test_fn_start: should not run
test_done: should not run
run_describe_finish: test suite beforeAll
run_describe_finish: ROOT_DESCRIBE_BLOCK
run_finish
unhandledErrors: 0",
}
`;
envinfo
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Configuring Jest
For example, with the following configuration jest will fail if there is less than 80% branch, line, and function coverage, or if there...
Read more >setup-polly-jest - npm
This helper provides a convenient way to use PollyJS (HTTP recording, replaying and stubbing tool) in your Jest/Jasmine tests.
Read more >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 >@jest/fake-timers | Yarn - Package Manager
Read below to learn how you can take part in improving Jest. Code of Conduct. Facebook has adopted a Code of Conduct that...
Read more >Internals API | Detox
Requires an installed worker. Reports about an error in the midst of beforeAll , beforeEach , afterEach , afterAll or any other hook....
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
Imo if
beforeAll
hook fail it should skip all related tests andafterAll
hook should be run in any case (to ensure clean up is done, becausebeforeAll
hook may initialize something partially)afterEach()
is also run in casebeforeAll()
fails. Is that a separate issue?