On jest, `afterEach(cleanup)` is too late to unmount a component using `useSyncExternalStore` with asynchronous updating
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- javascript, react
- Domain
- frontend, testing-qa
Research direction
Start by running the reproduction repository linked in the issue with Jest, React, and @testing-library/react. Investigate the timing between the test finishing and afterEach(cleanup), focusing on how useSyncExternalStore updates are handled during unmount. Done means the reproduction no longer logs the act warning while cleanup and existing behavior remain intact.
Written by the indexing model from the issue text.
Description
@testing-library/reactversion: 16.3.0reactversion: 19.2.0- Testing Framework and version:
jest: 30.2.0
- DOM Environment:
jsdom: 27.0.1
Relevant code or config:
None (please see reproduction repository described below)
What you did:
Testing a component using React's useSyncExternalStore and running the test without async
What happened:
useSyncExternalStore's update may happen just after finishing the test, but afterEach is not called in that timing, so the callback of useSyncExternalStore cannot handle 'unmounted' state, resulting the log An update to TestComponent inside a test was not wrapped in act(...)..
Reproduction:
I created a repositoy for the reproduction: https://github.com/jet2jet/testing-test
Problem description:
During just after finishing a test and just before afterEach, the test code cannot insert act() calls, so the problem An update to ... cannot be resolved with using act().
Suggested solution:
I think it's very difficult to call cleanup() just after finishing a test, but it's necessary to unmount, for resolving timing problem.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from testing-library/react-testing-library
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
testing-library/react-testing-library#1466 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
testing-library/react-testing-library#1459 · 2 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 35/100
testing-library/react-testing-library#1430 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
testing-library/react-testing-library#1419 · 3 comments ·
All issues in testing-library/react-testing-library
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
babalae/bettergi-scripts-list#3674 ·
-
ecosystem wording
Difficulty 1/5 Under an hour Newbie friendliness 90/100
matrix-org/matrix.org#3649 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
vadimdemedes/ink#1029 ·
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·