You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/13.x/docs/api/events/fire-event.mdx
+59-25Lines changed: 59 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,6 @@
1
1
# Fire Event API
2
2
3
-
```ts
4
-
function fireEvent(element:ReactTestInstance, eventName:string, ...data:unknown[]):void;
5
-
```
3
+
## `fireEvent`{#fire-event}
6
4
7
5
:::note
8
6
For common events like `press` or `type` it's recommended to use [User Event API](docs/api/events/user-event) as it offers
@@ -11,6 +9,10 @@ more realistic event simulation by emitting a sequence of events with proper eve
11
9
Use Fire Event for cases not supported by User Event and for triggering event handlers on composite components.
12
10
:::
13
11
12
+
```ts
13
+
function fireEvent(element:ReactTestInstance, eventName:string, ...data:unknown[]):void;
14
+
```
15
+
14
16
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.
15
17
16
18
Unlike User Event, this API does not automatically pass event object to event handler, this is responsibility of the user to construct such object.
@@ -57,14 +59,17 @@ FireEvent exposes convenience methods for common events like: `press`, `changeTe
It is recommended to use the User Event [`press()`](docs/api/events/user-event#press) helper instead as it offers more realistic simulation of press interaction, including pressable support.
66
64
:::
67
65
66
+
```tsx
67
+
fireEvent.press: (
68
+
element: ReactTestInstance,
69
+
...data: Array<any>,
70
+
) =>void
71
+
```
72
+
68
73
Invokes `press` event handler on the element or parent element in the tree.
It is recommended to use the User Event [`type()`](docs/api/events/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.
102
103
:::
103
104
105
+
```tsx
106
+
fireEvent.changeText: (
107
+
element: ReactTestInstance,
108
+
...data: Array<any>,
109
+
) =>void
110
+
```
111
+
104
112
Invokes `changeText` event handler on the element or parent element in the tree.
Prefer using [`user.scrollTo`](docs/api/events/user-event#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.
134
+
:::
135
+
136
+
```tsx
137
+
fireEvent.scroll: (
138
+
element: ReactTestInstance,
139
+
...data: Array<any>,
140
+
) =>void
126
141
```
127
142
128
143
Invokes `scroll` event handler on the element or parent element in the tree.
Prefer using [`user.scrollTo`](docs/api/events/user-event#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.
157
-
158
171
:::
159
172
160
-
## `fireEventAsync`
173
+
## `fireEventAsync`{#async}
161
174
162
175
:::info RNTL minimal version
163
176
@@ -190,24 +203,45 @@ Like `fireEvent`, `fireEventAsync` also provides convenience methods for common
It is recommended to use the User Event [`press()`](docs/api/events/user-event#press) helper instead as it offers more realistic simulation of press interaction, including pressable support.
208
+
:::
209
+
210
+
```tsx
211
+
fireEventAsync.press: (
212
+
element: ReactTestInstance,
213
+
...data: Array<any>,
214
+
) =>Promise<unknown>
195
215
```
196
216
197
-
Async version of `fireEvent.press` designed for React 19 and React Suspense. Use when press event handlers trigger suspense boundaries.
217
+
Async version of `fireEvent.press` designed for React 19 and React Suspense. Use when `press` event handlers trigger suspense boundaries.
It is recommended to use the User Event [`type()`](docs/api/events/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.
223
+
:::
224
+
225
+
```tsx
226
+
fireEventAsync.changeText: (
227
+
element: ReactTestInstance,
228
+
...data: Array<any>,
229
+
) =>Promise<unknown>
203
230
```
204
231
205
-
Async version of `fireEvent.changeText` designed for React 19 and React Suspense. Use when changeText event handlers trigger suspense boundaries.
232
+
Async version of `fireEvent.changeText` designed for React 19 and React Suspense. Use when `changeText` event handlers trigger suspense boundaries.
Prefer using [`user.scrollTo`](docs/api/events/user-event#scrollto) over `fireEventAsync.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior.
238
+
:::
239
+
240
+
```tsx
241
+
fireEventAsync.scroll: (
242
+
element: ReactTestInstance,
243
+
...data: Array<any>,
244
+
) =>Promise<unknown>
211
245
```
212
246
213
-
Async version of `fireEvent.scroll` designed for React 19 and React Suspense. Use when scroll event handlers trigger suspense boundaries.
247
+
Async version of `fireEvent.scroll` designed for React 19 and React Suspense. Use when `scroll` event handlers trigger suspense boundaries.
Copy file name to clipboardExpand all lines: website/docs/13.x/docs/api/render.mdx
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# `render` function
2
2
3
+
## `render`
4
+
3
5
```jsx
4
6
functionrender(
5
7
component:React.Element<any>,
@@ -20,32 +22,32 @@ test('basic test', () => {
20
22
21
23
> When using React context providers, like Redux Provider, you'll likely want to wrap rendered component with them. In such cases, it's convenient to create your own custom `render` method. [Follow this great guide on how to set this up](https://testing-library.com/docs/react-testing-library/setup#custom-render).
22
24
23
-
## Options
25
+
###Options
24
26
25
27
The behavior of the `render` method can be customized by passing various options as a second argument of the `RenderOptions` type:
26
28
27
-
### `wrapper` option
29
+
####`wrapper`
28
30
29
31
```ts
30
32
wrapper?:React.ComponentType<any>,
31
33
```
32
34
33
35
This option allows you to wrap the tested component, passed as the first option to the `render()` function, in an additional wrapper component. This is useful for creating reusable custom render functions for common React Context providers.
34
36
35
-
### `concurrentRoot` option{#concurrent-root}
37
+
####`concurrentRoot`{#concurrent-root}
36
38
37
39
Set to `false` to disable concurrent rendering.
38
40
Otherwise, `render` will default to using concurrent rendering used in the React Native New Architecture.
This option allows you to pass `createNodeMock` option to `ReactTestRenderer.create()` method in order to allow for custom mock refs. You can learn more about this option from [React Test Renderer documentation](https://reactjs.org/docs/test-renderer.html#ideas).
@@ -59,7 +61,7 @@ This **experimental** option allows you to replicate React Native behavior of th
59
61
60
62
React Test Renderer does not enforce this check; hence, by default, React Native Testing Library also does not check this. That might result in runtime errors when running your code on a device, while the code works without errors in tests.
61
63
62
-
## Result
64
+
###Result
63
65
64
66
The `render` function returns the same queries and utilities as the [`screen`](docs/api/screen) object. We recommended using the `screen` object as more developer-friendly way.
0 commit comments