@@ -35,7 +35,7 @@ more hooks for testing.
35
35
The `props` passed into the callback will be the `initialProps` provided in the `options` to
36
36
`renderHook`, unless new props are provided by a subsequent `rerender` call.
37
37
38
- ### `options`
38
+ ### `options` (Optional)
39
39
40
40
An options object to modify the execution of the `callback` function. See the
41
41
[`renderHook` Options](/reference/api#renderhook-options) section for more details.
@@ -69,15 +69,6 @@ The `renderHook` function returns an object that has the following properties:
69
69
The ` current ` value or the ` result ` will reflect whatever is returned from the ` callback ` passed to
70
70
` renderHook ` . Any thrown values will be reflected in the ` error ` value of the ` result ` .
71
71
72
- ### ` waitForNextUpdate `
73
-
74
- ` ` ` js
75
- function waitForNextUpdate (): Promise<void>
76
- ```
77
-
78
- - `waitForNextUpdate` (`function`) - returns a `Promise` that resolves the next time the hook
79
- renders, commonly when state is updated as the result of an asynchronous action.
80
-
81
72
### ` rerender `
82
73
83
74
` ` ` js
@@ -96,6 +87,11 @@ function unmount(): void
96
87
A function to unmount the test component. This is commonly used to trigger cleanup effects for
97
88
`useEffect` hooks.
98
89
90
+ ### `...asyncUtils`
91
+
92
+ Utilities to assist with testing asynchronous behaviour. See the
93
+ [Async Utils](/reference/api#async-utilities) section for more details.
94
+
99
95
---
100
96
101
97
## `act`
@@ -147,3 +143,66 @@ of the regular imports.
147
143
148
144
If neither of these approaches are suitable, setting the ` RHTL_SKIP_AUTO_CLEANUP ` environment
149
145
variable to ` true ` before importing ` @testing - library / react - hooks ` will also disable this feature.
146
+
147
+ ---
148
+
149
+ ## Async Utilities
150
+
151
+ ### ` waitForNextUpdate `
152
+
153
+ ` ` ` js
154
+ function waitForNextUpdate (options ?: WaitOptions ): Promise<void>
155
+ ```
156
+
157
+ Returns a `Promise` that resolves the next time the hook renders, commonly when state is updated as
158
+ the result of an asynchronous update.
159
+
160
+ See the [`wait` Options](/reference/api#wait-options) section for more details on the available
161
+ `options`.
162
+
163
+ ### `wait`
164
+
165
+ ```js
166
+ function wait(callback: function(): boolean|void, options?: WaitOptions): Promise<void>
167
+ ```
168
+
169
+ Returns a `Promise` that resolves if the provided callback executes without exception and returns a
170
+ truthy or `undefined` value. It is safe to use the [`result` of `renderHook`](/reference/api#result)
171
+ in the callback to perform assertion or to test values.
172
+
173
+ The callback is tested after each render of the hook. By default, errors raised from the callback
174
+ will be suppressed (`suppressErrors = true`).
175
+
176
+ See the [`wait` Options](/reference/api#wait-options) section for more details on the available
177
+ `options`.
178
+
179
+ ### `waitForValueToChange`
180
+
181
+ ```js
182
+ function waitForValueToChange(selector: function(): any, options?: WaitOptions): Promise<void>
183
+ ```
184
+
185
+ Returns a `Promise` that resolves if the value returned from the provided selector changes. It
186
+ expected that the [`result` of `renderHook`](/reference/api#result) to select the value for
187
+ comparison.
188
+
189
+ The value is selected for comparison after each render of the hook. By default, errors raised from
190
+ selecting the value will not be suppressed (`suppressErrors = false`).
191
+
192
+ See the [`wait` Options](/reference/api#wait-options) section for more details on the available
193
+ `options`.
194
+
195
+ ### `wait` Options
196
+
197
+ The async utilities accepts the following options:
198
+
199
+ #### `timeout`
200
+
201
+ The maximum amount of time in milliseconds (ms) to wait. By default, no timeout is applied.
202
+
203
+ #### `suppressErrors`
204
+
205
+ If this option is set to `true`, any errors that occur while waiting are treated as a failed check.
206
+ If this option is set to `false`, any errors that occur while waiting cause the promise to be
207
+ rejected. Please refer to the [utility descriptions](/reference/api#async-utilities) for the default
208
+ values of this option (if applicable).
0 commit comments