The act Utility in React Testing Library
React Testing Library re-exports everything from DOM Testing Library and explicitly lists act as a core top-level API method alongside render and renderHook, making it available as a named export from the framework package without requiring a separate wrapper.
WHY IT EXISTS: Testing Library organizes its ecosystem into layers so that framework-specific packages do not duplicate shared primitives. React Testing Library focuses on React component mounting, unmounting, and hydration while delegating common query and interaction utilities to DOM Testing Library. The act utility exists in this boundary as a named export that React Testing Library surfaces directly rather than hiding inside render options or result objects. This layering keeps the framework package thin.
THE MENTAL MODEL: Think of the React Testing Library API surface as two buckets. The first bucket is everything inherited from DOM Testing Library. The second bucket is a short list of React-specific methods that includes render, renderHook, and act. act is not a child property returned by render. It is a module-level peer that sits at the same hierarchy level as the rendering functions themselves. You import it directly instead of extracting it from a rendered component instance.
HOW IT WORKS: The documentation enumerates exports in a specific order. After describing the render function, its options, and its result object including helpers like cleanup, the page lists act as a standalone section before moving on to renderHook. This placement signals that act is a general-purpose primitive available for direct import from the package rather than a configuration flag or a query modifier. It is not nested under render results or options.
WHEN TO USE IT: Reach for act when you need a top-level utility that the package explicitly groups with render, cleanup, and renderHook as part of its public API contract. If you are scanning the React Testing Library API page for available named exports, act appears as a first-class citizen alongside the primary rendering functions. Use it when you want the utility that the documentation positions between render lifecycle helpers and hook testing.
WHEN NOT TO USE IT: Do not look for detailed act usage examples or signature documentation inside the React Testing Library render sections. The source material enumerates act as an export without expanding its arguments, return value, or interaction model. If you need behavioral details, you must consult the underlying DOM Testing Library documentation or the React act documentation itself rather than the React Testing Library render guide. Do not assume it is a React-specific wrapper based solely on this page.
ONE CANONICAL EXAMPLE: The API page lists act immediately after cleanup and before renderHook in the method enumeration, showing its position as a core utility between render lifecycle helpers and hook testing. This ordering is the canonical evidence of its top-level status in the package.
Read the original → testing-library.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.