Skip to content

Commit 52d3d5d

Browse files
committed
.
1 parent efa9937 commit 52d3d5d

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

docs/api/fire-event.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ The `fireEvent` API triggers event handlers on both host and composite component
1515

1616
Unlike User Event, this API does not automatically pass event object to event handler, this is responsibility of the user to construct such object.
1717

18+
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.
19+
1820
This function uses async `act` internally to execute all pending React updates during event handling.
1921

2022
```jsx
@@ -64,11 +66,11 @@ FireEvent exposes convenience methods for common events like: `press`, `changeTe
6466
```tsx
6567
fireEvent.press: (
6668
instance: TestInstance,
67-
...data: Array<any>,
68-
) => Promise<unknown>
69+
eventProps?: Record<string, unknown>,
70+
) => Promise<void>
6971
```
7072

71-
Invokes `press` event handler on the element or parent element in the tree.
73+
Builds a press event object, merges `eventProps` into it, and invokes the `press` handler on the element or nearest eligible parent.
7274

7375
```jsx
7476
import { View, Text, TouchableOpacity } from 'react-native';
@@ -91,7 +93,7 @@ await render(
9193
);
9294

9395
await fireEvent.press(screen.getByText('Press me'), eventData);
94-
expect(onPressMock).toHaveBeenCalledWith(eventData);
96+
expect(onPressMock).toHaveBeenCalledWith(expect.objectContaining(eventData));
9597
```
9698

9799
### `fireEvent.changeText`
@@ -102,8 +104,8 @@ expect(onPressMock).toHaveBeenCalledWith(eventData);
102104
```tsx
103105
fireEvent.changeText: (
104106
instance: TestInstance,
105-
...data: Array<any>,
106-
) => Promise<unknown>
107+
text: string,
108+
) => Promise<void>
107109
```
108110

109111
Invokes `changeText` event handler on the element or parent element in the tree.
@@ -132,11 +134,11 @@ await fireEvent.changeText(screen.getByPlaceholderText('Enter data'), CHANGE_TEX
132134
```tsx
133135
fireEvent.scroll: (
134136
instance: TestInstance,
135-
...data: Array<any>,
136-
) => Promise<unknown>
137+
eventProps?: Record<string, unknown>,
138+
) => Promise<void>
137139
```
138140

139-
Invokes `scroll` event handler on the element or parent element in the tree.
141+
Builds a scroll event object, merges `eventProps` into it, and invokes the `scroll` handler on the element or nearest eligible parent.
140142

141143
#### On a `ScrollView`
142144

docs/api/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ React Native Testing Library consists of following APIs:
1212
- [Fire Event](./fire-event.md) - simulate any component event in a simplified way purposes
1313
- Misc APIs:
1414
- [`renderHook` function](./render-hook.md) - render hooks for testing
15-
- [Async utils](./async-utilities.md): `findBy*` queries, `wait`, `waitForElementToBeRemoved`
15+
- [Async utils](./async-utilities.md): `findBy*` queries, `waitFor`, `waitForElementToBeRemoved`
1616
- [Configuration](./configuration.md): `configure`, `resetToDefaults`
1717
- [Accessibility](./accessibility.md): `isHiddenFromAccessibility`
1818
- [Other](./other-helpers.md): `within`, `act`, `cleanup`

docs/api/queries.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ expect(
397397
).not.toBeOnTheScreen();
398398

399399
// Include hidden elements
400-
expect(screen.getByText('Hidden from accessibility')).toBeOnTheScreen();
401400
expect(
402401
screen.getByText('Hidden from accessibility', { includeHiddenElements: true }),
403402
).toBeOnTheScreen();

0 commit comments

Comments
 (0)