React Testing Library

act

https://testing-library.com/docs/react-testing-library/cheatsheet/#events

React Testing Library wraps render and fireEvent in a call to act already so most cases should not require using it manually

Where can this be found in the source?

dom-testing-library’s fireEvent function calls the configured eventWrapper, passing it the actual call to dispatch the event:

@testing-library/dom —> src/events.js

function fireEvent(element, event) {
  return getConfig().eventWrapper(() => {
    //...
    return element.dispatchEvent(event)
  })
}

What is eventWrapper? In RTL, the eventWrapper is configured to wrap the call to the callback in a call to React’s act():

@testing-library/react —> src/pure.js

import {
  //...
  configure as configureDTL,
} from '@testing-library/dom'
import act, {
  //...
} from './act-compat'
//...
configureDTL({
  //...
  eventWrapper: cb => {
    let result
    act(() => {
      result = cb()
    })
    return result
  },
})