Skip to content

Commit 0927137

Browse files
committed
docs: Add more details to the fireEvent api documentation.
1 parent 5145a70 commit 0927137

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

docs/API.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,13 @@ test('Component has a structure', () => {
140140

141141
## `fireEvent`
142142

143-
Invokes given event handler on the element bubbling to the root of the rendered tree.
143+
Invokes a given event handler (whether native or custom) on the element, bubbling to the root of the rendered tree. The three most common events (`press`, `changeText`, and `scroll`) have been aliased for convenience.
144144

145145
### `fireEvent: (element: ReactTestInstance, eventName: string, data?: *) => void`
146146

147147
Invokes named event handler on the element or parent element in the tree. For better readability, `fireEvent` strips the `on` part of the handler prop name, so it will fire `onMyCustomEvent` when `myCustomEvent` is passed as `eventName`.
148148

149149
```jsx
150-
import { View } from 'react-native';
151150
import { render, fireEvent } from 'react-native-testing-library';
152151
import { MyComponent } from './MyComponent';
153152

@@ -159,6 +158,23 @@ const { getByTestId } = render(
159158
fireEvent(getByTestId('custom'), 'myCustomEvent');
160159
```
161160

161+
An example using `fireEvent` with native events that aren't already aliased by the `fireEvent` api.
162+
163+
```jsx
164+
import { TextInput, View } from 'react-native';
165+
import { fireEvent, render } from 'react-native-testing-library';
166+
167+
const onBlurMock = jest.fn();
168+
169+
const { getByPlaceholder } = render(
170+
<View>
171+
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
172+
</View>
173+
);
174+
175+
fireEvent(getByPlaceholder('my placeholder'), 'blur');
176+
```
177+
162178
### `fireEvent.press: (element: ReactTestInstance) => void`
163179

164180
Invokes `press` event handler on the element or parent element in the tree.

0 commit comments

Comments
 (0)