act() makes sure React has finished all updates before you check the DOM. With RTL (React Testing Library), you rarely call it, because RTL already does it for you.
act(callback) processes every update the callback causes, such as renders, state updates and effects. It applies them to the DOM before your assertions run. Without it, your test could check the DOM before React finished. React also warns about updates not wrapped in act.
In React 19, import act from react. The version from react-dom/test-utils is deprecated. Use await act(async () => ...) when the work is async.
RTL already wraps render, fireEvent and its user-event integration in act. For updates that happen later, like data arriving after a fetch, use findBy queries or waitFor. They retry until the assertion passes.
An act warning in an RTL test usually means an update happened after the test stopped waiting.
actprocesses renders, effects and updates before your assertions.- In React 19, import it from
react, and use the async form withawait. - RTL already wraps
renderand events inact. - Use
findByorwaitForfor async updates. - An
actwarning usually means an update you did not wait for.