tl;dr: It wraps some work you'd like to do and waits for that work to complete before returning
An update to Component inside a test was not wrapped in act(...).
tl;dr: A React component is updating (probably as a result of changing state, props, or hooks) but that update is not happening inside of something wrapped in act.
- Implemented in ReactFiberWorkLoop
- That error is produced when running react in a test environment (not sure how it knows this tbh) and
actQueueis null (actQueueis set whenactis called) - Produced while calling
scheduleUpdateOnFiber, which is ?probably? called as a result of changing state or props
Here is where act is implemented.
React Testing Library calls act for you when calling render as well as when calling fireEvent (this and this)
FYI - act is only callable in developer mode - otherwise it will throw an exception
actcreates a new actQueue or uses the current one if it exists already- then it calls the block passed in (the code you're wrapping in
act)- that passed in block does the work you specified in your test
- that work causes state and props to update, and eventually
ReactFiberRootScheduler.scheduleCallbackis called by react, which pushes work onto the actactQueue
- then it flushes the current
actQueueby executing every work item in it - then it sets
actQueue = null(here for synchronous callbacks, here for async callbacks)