fireEvent
For common events like press
or type
it's recommended to use User Event API as it offers
more realistic event simulation by emitting a sequence of events with proper event objects that mimic React Native runtime behavior.
Use Fire Event for cases not supported by User Event and for triggering event handlers on composite components.
The fireEvent
API allows you to trigger all kinds of event handlers on both host and composite components. It will try to invoke a single event handler traversing the component tree bottom-up from passed element and trying to find enabled event handler named onXxx
when xxx
is the name of the event passed.
Unlike User Event, this API does not automatically pass event object to event handler, this is responsibility of the user to construct such object.
fireEvent
performs checks that should prevent events firing on disabled elements.
An example using fireEvent
with native events that aren't already aliased by the fireEvent
api.
FireEvent exposes convenience methods for common events like: press
, changeText
, scroll
.
fireEvent.press
It is recommended to use the User Event press()
helper instead as it offers more realistic simulation of press interaction, including pressable support.
Invokes press
event handler on the element or parent element in the tree.
fireEvent.changeText
It is recommended to use the User Event type()
helper instead as it offers more realistic simulation of text change interaction, including key-by-key typing, element focus, and other editing events.
Invokes changeText
event handler on the element or parent element in the tree.
fireEvent.scroll
Prefer using user.scrollTo
over fireEvent.scroll
for ScrollView
, FlatList
, and SectionList
components. User Event provides a more realistic event simulation based on React Native runtime behavior.
Invokes scroll
event handler on the element or parent element in the tree.
ScrollView
Prefer using user.scrollTo
over fireEvent.scroll
for ScrollView
, FlatList
, and SectionList
components. User Event provides a more realistic event simulation based on React Native runtime behavior.
fireEventAsync
This API requires RNTL v13.3.0 or later.
The fireEventAsync
function is the async version of fireEvent
designed for working with React 19 and React Suspense. This function uses async act
function internally to ensure all pending React updates are executed during event handling.
Like fireEvent
, fireEventAsync
also provides convenience methods for common events: fireEventAsync.press
, fireEventAsync.changeText
, and fireEventAsync.scroll
.
fireEventAsync.press
It is recommended to use the User Event press()
helper instead as it offers more realistic simulation of press interaction, including pressable support.
Async version of fireEvent.press
designed for React 19 and React Suspense. Use when press
event handlers trigger suspense boundaries.
fireEventAsync.changeText
It is recommended to use the User Event type()
helper instead as it offers more realistic simulation of text change interaction, including key-by-key typing, element focus, and other editing events.
Async version of fireEvent.changeText
designed for React 19 and React Suspense. Use when changeText
event handlers trigger suspense boundaries.
fireEventAsync.scroll
Prefer using user.scrollTo
over fireEventAsync.scroll
for ScrollView
, FlatList
, and SectionList
components. User Event provides a more realistic event simulation based on React Native runtime behavior.
Async version of fireEvent.scroll
designed for React 19 and React Suspense. Use when scroll
event handlers trigger suspense boundaries.