Q49: What is the act() helper function in React testing?
act() guarantees that all rendering updates, state changes, and effect side-effects completed before assertions run, preventing async state update warnings during unit testing.
Key Takeaways
Flushes all state updates and pending effects before test assertions execute.
React Testing Library wraps user interaction helpers (
userEvent,fireEvent) inact()automatically.
Knowledge Check
What warning does wrapping state triggering code in act() eliminate during testing?