TLDR Dev · ARTICLES & TUTORIALS

ABSOLUTELY EVERYTHING YOU NEED TO KNOW ABOUT ACT() IN REACT TESTS

howtotestfrontend.com8 min read

Summary from the TLDR Dev newsletter

The `act()` function in React tests makes sure that all state changes and side effects are fully processed before assertions run, preventing tests from checking against outdated state values. While React Testing Library functions like `userEvent` and `findBy...` automatically wrap their operations in `act()`, you'll need to manually use it when testing hooks with state changes, directly calling DOM methods like `button.click()`, or manually dispatching events.