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.
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.
fireEvent.press
Use the User Event press() helper instead. It simulates press interactions more realistically, including pressable support.
Invokes press event handler on the element or parent element in the tree.
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.
Invokes scroll event handler on the element or parent element in the tree.
