Repository navigation
Enable restoreMocks in Vitest and remove manual vi.restoreAllMocks() calls - #483
Merged
Merged
Conversation
oscarlorentzon
approved these changes
Oct 13, 2026
mrxz
force-pushed
the
vitest-restore-mocks
branch
from
October 14, 2026 09:52
0524fb9 to
16079a5
Compare
Contributor
|
Need a small rebase |
mrxz
force-pushed
the
vitest-restore-mocks
branch
from
October 16, 2026 09:45
16079a5 to
38426d2
Compare
Collaborator
Author
|
@dmarcos I've rebased it. |
Contributor
|
Thank you! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Noticed while writing unit tests for #463 that the majority of unit test files include an
afterEachcallback for restoring all mocks throughvi.restoreAllMocks(). Vitest offers a convenience feature that automatically calls this method before each test (see https://vitest.dev/config/restoremocks#restoremocks).This PR enables
restoreMocksin thevite.config.tsand removes theafterEachcallbacks from the unit tests.This does mean the timing changes slightly, from after tests to before tests, but this should be indistinguishable. It now also happens unconditionally, though most likely the snippet would've been copied in most tests files anyway. As mentioned in the Vitest documentation it can cause issue when using
test.concurrent, but I don't see any immediate reason where we'd start using that.