Skip to content

Commit af067d0

Browse files
danahartwegthymikee
authored andcommitted
docs: Add more details to the fireEvent api documentation. (#102)
1 parent 6d4d426 commit af067d0

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
@@ -148,14 +148,13 @@ test('Component has a structure', () => {
148148

149149
## `fireEvent`
150150

151-
Invokes given event handler on the element bubbling to the root of the rendered tree.
151+
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.
152152

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

155155
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`.
156156

157157
```jsx
158-
import { View } from 'react-native';
159158
import { render, fireEvent } from 'react-native-testing-library';
160159
import { MyComponent } from './MyComponent';
161160

@@ -167,6 +166,23 @@ const { getByTestId } = render(
167166
fireEvent(getByTestId('custom'), 'myCustomEvent');
168167
```
169168

169+
An example using `fireEvent` with native events that aren't already aliased by the `fireEvent` api.
170+
171+
```jsx
172+
import { TextInput, View } from 'react-native';
173+
import { fireEvent, render } from 'react-native-testing-library';
174+
175+
const onBlurMock = jest.fn();
176+
177+
const { getByPlaceholder } = render(
178+
<View>
179+
<TextInput placeholder="my placeholder" onBlur={onBlurMock} />
180+
</View>
181+
);
182+
183+
fireEvent(getByPlaceholder('my placeholder'), 'blur');
184+
```
185+
170186
### `fireEvent.press: (element: ReactTestInstance) => void`
171187

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

0 commit comments

Comments
 (0)