fix: stop printing the same error for each individual test caused by beforeAll when it fails #10004
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Closes #9901
From my research, I found that the call of
addErrorToEachTestUnderDescribe
was causing this bug (line 160):https://github.com/facebook/jest/blob/0a4e4a1657b42b21ebf3a969fbf3bbdd28ca930f/packages/jest-circus/src/eventHandler.ts#L154-L170
Removing this function call would stop printing error messages from beforeAll failure for each individual test, however, test suit would pass even though
beforeAll
failed. That's why I had to add an error tostate.unhandledErrors
, so it fails the test suit and prints an error message forbeforeAll
failure.Since the code is the same as as-if statement for
afterAll
type, I joinedtype === 'beforeAll'
andtype === 'afterAll'
.These changes haven't broken any existing test in the project, and it looks like it is much less confusing comparing to the previous version, though I would like to get confirmation that this is the expected behaviour.
Test plan
Let's reuse the example from the issue description and see a new behaviour that this bug fix provides.
Example:
New behaviour: