Skip to content

Commit 068be8f

Browse files
committed
add note user.scrollTo in favour of fireEvent.scroll and edit broken links
1 parent 21254b0 commit 068be8f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

website/docs/API.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,16 @@ render(
396396
fireEvent.scroll(screen.getByText('scroll-view'), eventData);
397397
```
398398

399+
:::note
400+
Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `FlatList`, `SectionList` and `ScrollView` components.
401+
User Event provides a more reliable and realistic event simulation that is suitable for React Native.
402+
:::
403+
399404
## Helper functions
400405

401406
### `waitFor`
402407

403-
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitFor.test.tsx)
408+
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/wait-for.test.tsx)
404409

405410
Defined as:
406411

@@ -414,7 +419,7 @@ function waitFor<T>(
414419
Waits for a period of time for the `expectation` callback to pass. `waitFor` may run the callback a number of times until timeout is reached, as specified by the `timeout` and `interval` options. The callback must throw an error when the expectation is not met. Returning any value, including a falsy one, will be treated as meeting the expectation, and the callback result will be returned to the caller of `waitFor` function.
415420

416421
```tsx
417-
await waitFor(() => expect(mockFunction).toHaveBeenCalledWith()))
422+
await waitFor(() => expect(mockFunction).toHaveBeenCalledWith())
418423
```
419424

420425
`waitFor` function will be executing `expectation` callback every `interval` (default: every 50 ms) until `timeout` (default: 1000 ms) is reached. The repeated execution of callback is stopped as soon as it does not throw an error, in such case the value returned by the callback is returned to `waitFor` caller. Otherwise, when it reaches the timeout, the final error thrown by `expectation` will be re-thrown by `waitFor` to the calling code.
@@ -504,7 +509,7 @@ If you receive warnings related to `act()` function consult our [Undestanding Ac
504509

505510
### `waitForElementToBeRemoved`
506511

507-
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitForElementToBeRemoved.test.tsx)
512+
- [`Example code`]https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/wait-for-element-to-be-removed.test.tsx)
508513

509514
Defined as:
510515

0 commit comments

Comments
 (0)