From 068be8f6f40428c113842fafeac6d81f7db4d541 Mon Sep 17 00:00:00 2001 From: vanGalilea Date: Thu, 4 Jan 2024 15:47:48 +0100 Subject: [PATCH 1/2] add note user.scrollTo in favour of fireEvent.scroll and edit broken links --- website/docs/API.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/website/docs/API.md b/website/docs/API.md index f5e2c818d..d2658cd87 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -396,11 +396,16 @@ render( fireEvent.scroll(screen.getByText('scroll-view'), eventData); ``` +:::note +Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `FlatList`, `SectionList` and `ScrollView` components. +User Event provides a more reliable and realistic event simulation that is suitable for React Native. +::: + ## Helper functions ### `waitFor` -- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitFor.test.tsx) +- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/wait-for.test.tsx) Defined as: @@ -414,7 +419,7 @@ function waitFor( 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. ```tsx -await waitFor(() => expect(mockFunction).toHaveBeenCalledWith())) +await waitFor(() => expect(mockFunction).toHaveBeenCalledWith()) ``` `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 ### `waitForElementToBeRemoved` -- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/waitForElementToBeRemoved.test.tsx) +- [`Example code`]https://github.com/callstack/react-native-testing-library/blob/main/src/__tests__/wait-for-element-to-be-removed.test.tsx) Defined as: From 5ee74aa4fa6e7fcce1514085fd40d3c573be8650 Mon Sep 17 00:00:00 2001 From: Maciej Jastrzebski Date: Wed, 10 Jan 2024 13:05:53 +0100 Subject: [PATCH 2/2] Update website/docs/API.md --- website/docs/API.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/website/docs/API.md b/website/docs/API.md index d2658cd87..ebd447451 100644 --- a/website/docs/API.md +++ b/website/docs/API.md @@ -397,8 +397,9 @@ fireEvent.scroll(screen.getByText('scroll-view'), eventData); ``` :::note -Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `FlatList`, `SectionList` and `ScrollView` components. -User Event provides a more reliable and realistic event simulation that is suitable for React Native. + +Prefer using [`user.scrollTo`](./UserEvent.md#scrollto) over `fireEvent.scroll` for `ScrollView`, `FlatList`, and `SectionList` components. User Event provides a more realistic event simulation based on React Native runtime behavior. + ::: ## Helper functions