Fire Event API
fireEvent
For common events like press or type, use the User Event API. It simulates events more realistically 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 triggers event handlers on both host and composite components. It traverses the component tree bottom-up from the passed element to find an enabled event handler named onXxx where xxx is the event name.
Unlike User Event, this API does not automatically pass event object to event handler, this is responsibility of the user to construct such object.
The base fireEvent(instance, eventName, ...data) API can pass multiple custom arguments to the handler. Convenience helpers such as fireEvent.press and fireEvent.scroll are different: they create a default event object and accept one optional object to merge into it.
This function uses async act internally to execute all pending React updates during event handling.
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, layout.
fireEvent.press
Use the User Event press() helper instead. It simulates press interactions more realistically, including pressable support.
Builds a press event object, merges eventProps into it, and invokes the press handler on the element or nearest eligible parent.
fireEvent.changeText
Use the User Event type() helper instead. It simulates text change interactions more realistically, 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 user.scrollTo over fireEvent.scroll for ScrollView, FlatList, and SectionList components. User Event simulates events more realistically based on React Native runtime behavior.
Builds a scroll event object, merges eventProps into it, and invokes the scroll handler on the element or nearest eligible parent.
On a ScrollView
fireEvent.layout
Available since React Native Testing Library 14.1.0.
Builds a layout event carrying the given layout rectangle and invokes the layout handler on the element or nearest eligible parent. Use it to simulate the layout engine measuring an element, e.g. to test components that adapt to a measured size.
The layout values are merged onto a zeroed rectangle ({ x: 0, y: 0, width: 0, height: 0 }), so pass only the fields your component reads.
