The warning means React saw a state update that your test didn't wait for. Fix it by waiting for the result of that update.
RTL (React Testing Library) already wraps render, user-event and its async utilities in act. act is React's helper that applies updates before you assert. So the warning usually means something async finished after your last await.
A typical case:
- The test asserts the loading state and ends.
- Then the fetch resolves and calls
setStatewhile the test is tearing down. - Your test never checked the final UI, so it may hide a bug.
The proper fix is to wait for the result of that update:
await screen.findBy*the loaded content.- Or
await waitFor(...)the state you expect. - For timers, advance fake timers inside
act, or use theadvanceTimersoption of user-event.
Wrapping random code in act to silence the warning is the wrong fix. If the component does work you don't care about in this test, mock that work or let it finish anyway.
- The warning means a state update happened after the point the test waited for.
- RTL already wraps render, events and its async utilities in
act. - Fix it by awaiting the UI change with
findBy*orwaitFor. - Don't add
acteverywhere just to silence the warning. - Common causes are unresolved fetches, timers and effects after the last assertion.
Read more