You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Material UI they have setup file that cleans DOM in afterEach. They also use sequence.hooks: "list", which made their setup file run before ours. This caused automatic snapshots to be empty.
Now we'll look for sequence.hooks config when deciding whether setup file should be in the start of end. Also noticed Vitest bug (or feature) where callbacks returned from beforeEach(() => () => void) were always run last. Now using explicit afterEach to work-around that.
How to test
Added test cases that fail without the fix. Revert the changes and see tests fail.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
❌ Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.48%. Comparing base (89f7beb) to head (7a90b6c). ⚠️ Report is 2 commits behind head on main.
AriPerkkio
changed the title
fix(vitest): afterEach not called when sequence.hooks is set
fix(vitest): afterEach not called early when sequence.hooks is set
Apr 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Issue:
before*hooks cleanup functions vitest-dev/vitest#10230What Changed
In Material UI they have setup file that cleans DOM in
afterEach. They also usesequence.hooks: "list", which made their setup file run before ours. This caused automatic snapshots to be empty.Now we'll look for
sequence.hooksconfig when deciding whether setup file should be in the start of end. Also noticed Vitest bug (or feature) where callbacks returned frombeforeEach(() => () => void)were always run last. Now using explicitafterEachto work-around that.How to test
Added test cases that fail without the fix. Revert the changes and see tests fail.