Skip to content

Commit b96bb2b

Browse files
committed
docs: suspense docs
1 parent 196680b commit b96bb2b

File tree

3 files changed

+67
-35
lines changed

3 files changed

+67
-35
lines changed

website/docs/13.x/docs/api/events/fire-event.mdx

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Fire Event API
22

3-
```ts
4-
function fireEvent(element: ReactTestInstance, eventName: string, ...data: unknown[]): void;
5-
```
3+
## `fireEvent` {#fire-event}
64

75
:::note
86
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
119
Use Fire Event for cases not supported by User Event and for triggering event handlers on composite components.
1210
:::
1311

12+
```ts
13+
function fireEvent(element: ReactTestInstance, eventName: string, ...data: unknown[]): void;
14+
```
15+
1416
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.
1517

1618
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
5759

5860
### `fireEvent.press` {#press}
5961

60-
```
61-
fireEvent.press: (element: ReactTestInstance, ...data: Array<any>) => void
62-
```
63-
6462
:::note
6563
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.
6664
:::
6765

66+
```tsx
67+
fireEvent.press: (
68+
element: ReactTestInstance,
69+
...data: Array<any>,
70+
) => void
71+
```
72+
6873
Invokes `press` event handler on the element or parent element in the tree.
6974

7075
```jsx
@@ -93,14 +98,17 @@ expect(onPressMock).toHaveBeenCalledWith(eventData);
9398

9499
### `fireEvent.changeText` {#change-text}
95100

96-
```
97-
fireEvent.changeText: (element: ReactTestInstance, ...data: Array<any>) => void
98-
```
99-
100101
:::note
101102
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.
102103
:::
103104

105+
```tsx
106+
fireEvent.changeText: (
107+
element: ReactTestInstance,
108+
...data: Array<any>,
109+
) => void
110+
```
111+
104112
Invokes `changeText` event handler on the element or parent element in the tree.
105113

106114
```jsx
@@ -121,8 +129,15 @@ fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEXT);
121129

122130
### `fireEvent.scroll` {#scroll}
123131

124-
```
125-
fireEvent.scroll: (element: ReactTestInstance, ...data: Array<any>) => void
132+
:::note
133+
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
126141
```
127142

128143
Invokes `scroll` event handler on the element or parent element in the tree.
@@ -152,12 +167,10 @@ fireEvent.scroll(screen.getByText('scroll-view'), eventData);
152167
```
153168

154169
:::note
155-
156170
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-
158171
:::
159172

160-
## `fireEventAsync`
173+
## `fireEventAsync` {#async}
161174

162175
:::info RNTL minimal version
163176

@@ -190,24 +203,45 @@ Like `fireEvent`, `fireEventAsync` also provides convenience methods for common
190203

191204
### `fireEventAsync.press` {#async-press}
192205

193-
```
194-
fireEventAsync.press: (element: ReactTestInstance, ...data: Array<any>) => Promise<unknown>
206+
:::note
207+
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>
195215
```
196216

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.
198218

199219
### `fireEventAsync.changeText` {#async-change-text}
200220

201-
```
202-
fireEventAsync.changeText: (element: ReactTestInstance, ...data: Array<any>) => Promise<unknown>
221+
:::note
222+
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>
203230
```
204231

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.
206233

207234
### `fireEventAsync.scroll` {#async-scroll}
208235

209-
```
210-
fireEventAsync.scroll: (element: ReactTestInstance, ...data: Array<any>) => Promise<unknown>
236+
:::note
237+
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>
211245
```
212246

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.

website/docs/13.x/docs/api/events/user-event.mdx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ Events will not be emitted if the `editable` prop is set to `false`.
226226
227227
## `scrollTo()` \{#scroll-to}
228228
229-
:::note
230-
`scrollTo` interaction has been introduced in RNTL v12.4.0.
231-
:::
232-
233229
```ts
234230
scrollTo(
235231
element: ReactTestInstance,

website/docs/13.x/docs/api/render.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `render` function
22

3+
## `render`
4+
35
```jsx
46
function render(
57
component: React.Element<any>,
@@ -20,32 +22,32 @@ test('basic test', () => {
2022

2123
> 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).
2224
23-
## Options
25+
### Options
2426

2527
The behavior of the `render` method can be customized by passing various options as a second argument of the `RenderOptions` type:
2628

27-
### `wrapper` option
29+
#### `wrapper`
2830

2931
```ts
3032
wrapper?: React.ComponentType<any>,
3133
```
3234

3335
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.
3436

35-
### `concurrentRoot` option {#concurrent-root}
37+
#### `concurrentRoot` {#concurrent-root}
3638

3739
Set to `false` to disable concurrent rendering.
3840
Otherwise, `render` will default to using concurrent rendering used in the React Native New Architecture.
3941

40-
### `createNodeMock` option
42+
#### `createNodeMock` {#create-node-mock}
4143

4244
```ts
4345
createNodeMock?: (element: React.Element) => unknown,
4446
```
4547

4648
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).
4749

48-
### `unstable_validateStringsRenderedWithinText` option
50+
#### `unstable_validateStringsRenderedWithinText`
4951

5052
```ts
5153
unstable_validateStringsRenderedWithinText?: boolean;
@@ -59,7 +61,7 @@ This **experimental** option allows you to replicate React Native behavior of th
5961

6062
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.
6163

62-
## Result
64+
### Result
6365

6466
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.
6567

0 commit comments

Comments
 (0)