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.

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:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
fider-apptimiacommented, Nov 4, 2020

Imo if beforeAll hook fail it should skip all related tests and afterAll hook should be run in any case (to ensure clean up is done, because beforeAll hook may initialize something partially)

0reactions
thernstigcommented, Mar 18, 2021

afterEach() is also run in case beforeAll() fails. Is that a separate issue?

Read more comments on GitHub >

github_iconTop 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 >

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