test(core): fix deprecated act() warnings + await expect().rejects#332
Merged
Conversation
kimyouknow
approved these changes
Mar 4, 2026
kimyouknow
left a comment
Collaborator
There was a problem hiding this comment.
@dev-dino22 Welcome and thank you for this contribution!
The PR description is well-structured with clear screenshots and references. Review confirms all changes are correct:
- ✅ Sync
act()→await act(async () => {})across 17 test files - ✅ Properly wraps bare mutations in
useMap.spec.tswithact()(the most meaningful fix) - ✅ Adds
awaittoexpect().rejectsinuseStorageState.spec.ts - ✅ All test functions correctly marked as
async - ✅ Helper function in
useImpressionRef.spec.tsalso properly converted
Great first contribution! 🎉
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.
Overview
Fix Warnings
1.
act()1.1. warnings
Updates were not wrapped in
act(), causing warnings.The environment where we run tests (Node.js + jsdom) is not a real browser. However, wrapping updates in
act()ensures React simulates the exact scheduling and rendering sequence from a real browser environment.This guarantees assertions run after rendering is fully complete.
Reference: react.dev/reference/react/act
Thus, we wrapped update operations in
act()as follows:Commit: test(core): wrap useMap mutations in act()
1.2. await act(async () ⇒ {})
Additionally, React documentation states that synchronous
act()usage is not safe in all cases and the synchronous version may be deprecated in the future.This is because React now processes updates in priority-based batches, making it safer to wait for
act()completion before proceeding.Reference: react.dev/reference/react/act
Thus, we converted all synchronous
act()calls to asynchronous usage.Commit: test(core): replace deprecated sync act() with await act(async)
2. await expect(promise)
In
useStorageState.spec.ts, Promise-returningexpect()statements were used withoutawait.Vitest currently auto-waits these assertions at test end, but warns they will fail in the future.
Thus, we added
awaitto all Promise-based assertions.Commit: test(core): await expect().rejects in useStorageState tests
3. After Completion
Tests now complete without warnings.
Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?