renderHook function
Renders a test component that will call the provided callback, including any hooks it calls, every time it renders. Returns RenderHookResult object, which you can interact with.
diff --git a/12.x/cookbook/advanced/network-requests.html b/12.x/cookbook/advanced/network-requests.html index 18f2184e..ba679fe0 100644 --- a/12.x/cookbook/advanced/network-requests.html +++ b/12.x/cookbook/advanced/network-requests.html @@ -9,7 +9,7 @@ - + diff --git a/12.x/cookbook/basics/async-tests.html b/12.x/cookbook/basics/async-tests.html index cf909796..031e6501 100644 --- a/12.x/cookbook/basics/async-tests.html +++ b/12.x/cookbook/basics/async-tests.html @@ -9,7 +9,7 @@ - + @@ -48,7 +48,7 @@ // Follow-up assertions do not need to be async, as we already waited for sign in operation to complete expect( - screen.queryByRole('header', { name: 'Sign in to Hello World App' }) + screen.queryByRole('header', { name: 'Sign in to Hello World App' }), ).not.toBeOnTheScreen(); expect(screen.queryByLabelText('Username')).not.toBeOnTheScreen(); expect(screen.queryByLabelText('Password')).not.toBeOnTheScreen(); @@ -81,7 +81,7 @@ options?: { timeout: number; interval: number; - } + }, ): Promise<T>;
It accepts an expectation to be validated and repeats the check every defined interval until it no longer throws an error. Similarly to findBy* queries they accept timeout and interval options and have the same default values of 1000ms for timeout, and a checking interval of 50 ms.
This function is, in a way, the negation of waitFor as it expects the initial expectation to be true (not throw an error), only to turn invalid (start throwing errors) on subsequent runs. It operates using the same timeout and interval parameters as findBy* queries and waitFor.
waitForWaits 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.
act() function consult our #waitForElementToBeRemoved
Waits for non-deterministic periods of time until queried element is removed or times out. waitForElementToBeRemoved periodically calls expectation every interval milliseconds to determine whether the element has been removed or not.
However this behavior was different than the web one, and wouldn't always be straightforward to reason about. For instance it could match text nodes far from each other on the screen. It also prevented us from implementing the string precision API. From v9, this type of match will not work.
diff --git a/12.x/docs/migration/previous/v9.md b/12.x/docs/migration/previous/v9.md index cdeb8db7..f9aa897c 100644 --- a/12.x/docs/migration/previous/v9.md +++ b/12.x/docs/migration/previous/v9.md @@ -37,7 +37,7 @@ In v1.14 we've introduced a feature allowing to match text when it's spread acro const { getByText } = render(Alternatively, a default global timeout value can be set using the configure function:
It accepts an expectation to be validated and repeats the check every defined interval until it no longer throws an error. Similarly to findBy* queries they accept timeout and interval options and have the same default values of 1000ms for timeout, and a checking interval of 50 ms.
This function is, in a way, the negation of waitFor as it expects the initial expectation to be true (not throw an error), only to turn invalid (start throwing errors) on subsequent runs. It operates using the same timeout and interval parameters as findBy* queries and waitFor.
Waits for the expectation callback to pass. waitFor runs the callback multiple 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, is treated as meeting the expectation, and the callback result is returned to the caller.
expectation callback can be partially enfo
() => {
expect(someFunction).toHaveBeenCalledWith();
},
- { timeout: 10000 }
+ { timeout: 10000 },
);
If you receive warnings related to act() function consult our Understanding Act function document.
act() function consult our timeout?: number;
interval?: number;
onTimeout?: (error: Error) => Error;
- }
+ },
): Promise<T>;
Waits for non-deterministic periods of time until queried element is removed or times out. waitForElementToBeRemoved periodically calls expectation every interval milliseconds to determine whether the element has been removed or not.
render functionThe render function is the entry point for writing React Native Testing Library tests. It deeply renders the given React element and returns helpers to query the output. The function is async and uses async act internally, so all pending React updates run before it resolves. This works with async React features like Suspense boundaries and the use() hook.
If your v13 assertions expected the handler to receive exactly the object you passed to fireEvent.press() or fireEvent.scroll(), update them to use partial matching.
act is now asyncIt accepts an expectation to be validated and repeats the check every defined interval until it no longer throws an error. Similarly to findBy* queries they accept timeout and interval options and have the same default values of 1000ms for timeout, and a checking interval of 50 ms.
This function is, in a way, the negation of waitFor as it expects the initial expectation to be true (not throw an error), only to turn invalid (start throwing errors) on subsequent runs. It operates using the same timeout and interval parameters as findBy* queries and waitFor.
waitForWaits for the expectation callback to pass. waitFor may run the callback multiple times until the timeout is reached, as specified by the timeout and interval options. The callback must throw an error when the expectation isn't met. Returning any value, including a falsy one, is treated as meeting the expectation, and the callback result is returned to the caller of waitFor.
act() function consult our #waitForElementToBeRemoved
Waits until the queried element is removed or times out. waitForElementToBeRemoved periodically calls expectation every interval milliseconds to determine whether the element has been removed or not.
However this behavior was different than the web one, and wouldn't always be straightforward to reason about. For instance it could match text nodes far from each other on the screen. It also prevented us from implementing the string precision API. From v9, this type of match will not work.
diff --git a/docs/migration/previous/v9.md b/docs/migration/previous/v9.md index fc933c48..affc812a 100644 --- a/docs/migration/previous/v9.md +++ b/docs/migration/previous/v9.md @@ -37,7 +37,7 @@ In v1.14 we've introduced a feature allowing to match text when it's spread acro const { getByText } = render(