Feat(breaking): unify wait for element signature with testing library (#327)

* Change argument to options object

* Renamed `waitForElement` to `waitFor`

* Migration guide entry

* Fixed typescript check

* Update src/helpers/a11yAPI.js

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* (Nearly) Empty migration doc for ver. 2.0 (#326)

* Added migration docs section

* Added to docosaurus side bar

* Updated README

* Increased async test timeout

* Update website/docs/Migration20.md

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

* feat(breaking): remove legacy `debug` export (#328)

* Removed global `debug` functions

* Removed global `debug` from docs

* Cleanup

* Added migration section

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
This commit is contained in:
Maciej Jastrzebski
2020-05-18 17:49:54 +02:00
committed by Michał Pierzchała
parent 043f51d36c
commit 5e798bc2e3
12 changed files with 84 additions and 55 deletions
+7 -8
View File
@@ -313,29 +313,28 @@ fireEvent.scroll(getByType(ScrollView), eventData);
expect(onEndReached).toHaveBeenCalled();
```
## `waitForElement`
## `waitFor`
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/waitForElement.test.js)
- [`Example code`](https://github.com/callstack/react-native-testing-library/blob/master/src/__tests__/waitFor.test.js)
Defined as:
```jsx
function waitForElement<T>(
function waitFor<T>(
expectation: () => T,
timeout: number = 4500,
interval: number = 50
{ timeout: number = 4500, interval: number = 50 }
): Promise<T> {}
```
Waits for non-deterministic periods of time until your element appears or times out. `waitForElement` periodically calls `expectation` every `interval` milliseconds to determine whether the element appeared or not.
Waits for non-deterministic periods of time until your element appears or times out. `waitFor` periodically calls `expectation` every `interval` milliseconds to determine whether the element appeared or not.
```jsx
import { render, waitForElement } from 'react-testing-library';
import { render, waitFor } from 'react-testing-library';
test('waiting for an Banana to be ready', async () => {
const { getByText } = render(<Banana />);
await waitForElement(() => getByText('Banana ready'));
await waitFor(() => getByText('Banana ready'));
});
```
+29
View File
@@ -5,6 +5,35 @@ title: Migration to 2.0
This guides describes major steps involved in migrating your testing code from using React Native Testing Library version `1.x` to version `2.0`.
## WaitFor API changes
`waitForElement` function has been renamed to `waitFor` for consistency with React Testing Library. Additionally the signature has slightly changed from:
```jsx
export default function waitForElement<T>(
expectation: () => T,
timeout?: number,
interval?: number
: Promise<T> {
```
to:
```jsx
export default function waitFor<T>(
expectation: () => T,
{
timeout?: number,
interval?: number
}
): Promise<T> {
```
Both changes should improve code readibility.
:::note
Please note that in many cases `waitFor` call can be replaced by proper use of `findBy` asynchonous queries resulting in more streamlined test code.
:::
## Removed global `debug` function
+1 -1
View File
@@ -33,7 +33,7 @@ title: Queries
`findAllBy` queries return a promise which resolves to an array when any matching elements are found. The promise is rejected if no elements match after a default timeout of 4500ms.
:::info
`findBy` and `findAllBy` queries accept optional `waitForOptions` object argument which can contain `timeout` and `interval` properies which have the same meaning as respective arguments to [`waitForElement`](https://callstack.github.io/react-native-testing-library/docs/api#waitforelement) function.
`findBy` and `findAllBy` queries accept optional `waitForOptions` object argument which can contain `timeout` and `interval` properies which have the same meaning as respective options for [`waitFor`](https://callstack.github.io/react-native-testing-library/docs/api#waitfor) function.
:::
## Queries