@@ -211,8 +211,10 @@ fireEvent.changeText(getByTestId('text-input'), CHANGE_TEXT);
211
211
212
212
Invokes ` scroll ` event handler on the element or parent element in the tree.
213
213
214
+ #### On a ` ScrollView `
215
+
214
216
``` jsx
215
- import { ScrollView , TextInput } from ' react-native' ;
217
+ import { ScrollView , Text } from ' react-native' ;
216
218
import { render , fireEvent } from ' react-native-testing-library' ;
217
219
218
220
const onScrollMock = jest .fn ();
@@ -233,6 +235,43 @@ const { getByTestId } = render(
233
235
fireEvent .scroll (getByTestId (' scroll-view' ), eventData);
234
236
```
235
237
238
+ #### On a ` FlatList `
239
+
240
+ ``` jsx
241
+ import { FlatList , View } from ' react-native' ;
242
+ import { render , fireEvent } from ' react-native-testing-library' ;
243
+
244
+ const onEndReached = jest .fn ();
245
+ const { getByType } = render (
246
+ < FlatList
247
+ data= {Array .from ({ length: 10 }, (_ , key ) => ({ key: ` ${ key} ` }))}
248
+ renderItem= {() => < View style= {{ height: 500 , width: 100 }} / > }
249
+ onEndReached= {onEndReached}
250
+ onEndReachedThreshold= {0.2 }
251
+ / >
252
+ );
253
+ const eventData = {
254
+ nativeEvent: {
255
+ contentOffset: {
256
+ y: 500 ,
257
+ },
258
+ contentSize: {
259
+ // Dimensions of the scrollable content
260
+ height: 500 ,
261
+ width: 100 ,
262
+ },
263
+ layoutMeasurement: {
264
+ // Dimensions of the device
265
+ height: 100 ,
266
+ width: 100 ,
267
+ },
268
+ },
269
+ };
270
+
271
+ fireEvent .scroll (getByType (ScrollView), eventData);
272
+ expect (onEndReached).toHaveBeenCalled ();
273
+ ```
274
+
236
275
## ` waitForElement `
237
276
238
277
- [ ` Example code ` ] ( https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/waitForElement.test.js )
0 commit comments