testing-library / testing-library/dom-testing-library
How to fix warning `An update to TimerRoot inside a test was not wrapped in act(...)` with timers?
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 3.3k
- Forks
- 474
- PR merge metrics
- No merged PRs in 30d
Description
tests are running correctly, but a warning appears in console. How can I fix this?
Warning: An update to TimerRoot inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
Demo - https://stackblitz.com/edit/vitejs-vite-7zbv1rkb?file=src%2FApp.test.tsx
Run npm run test
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.
Research direction
Reproduce the warning in the linked StackBlitz demo by running npm run test, starting with src/App.test.tsx named in the URL. Trace the timer-triggered update and confirm that the test run completes without the act(...) warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100