@@ -11,16 +11,17 @@ route: '/reference/api'
11
11
- [ ` act ` ] ( /reference/api#act )
12
12
- [ ` cleanup ` ] ( /reference/api#cleanup )
13
13
- [ ` addCleanup ` ] ( /reference/api#addcleanup )
14
+ - [ ` removeCleanup ` ] ( /reference/api#removecleanup )
14
15
15
16
---
16
17
17
18
## ` renderHook `
18
19
19
- ``` js
20
- function renderHook (
21
- callback : function (props ?: any ): any,
20
+ ``` ts
21
+ renderHook : (
22
+ callback : (props ?: any ): any ,
22
23
options ?: RenderHookOptions
23
- ): RenderHookResult
24
+ ) => RenderHookResult
24
25
```
25
26
26
27
Renders a test component that will call the provided ` callback ` , including any hooks it calls, every
@@ -61,7 +62,7 @@ The `renderHook` function returns an object that has the following properties:
61
62
62
63
### ` result `
63
64
64
- ```js
65
+ ``` ts
65
66
{
66
67
all : Array < any >
67
68
current : any ,
@@ -77,22 +78,33 @@ returned at the time.
77
78
78
79
### ` rerender `
79
80
80
- ` ` ` js
81
- function rerender (newProps ?: any ): void
81
+ ``` ts
82
+ rerender : (newProps ? : any ) => void
82
83
```
83
84
84
85
A function to rerender the test component, causing any hooks to be recalculated. If ` newProps ` are
85
86
passed, they will replace the ` callback ` function's ` initialProps ` for subsequent rerenders.
86
87
87
88
### ` unmount `
88
89
89
- ```js
90
- function unmount(): void
90
+ ``` ts
91
+ unmount : () => void
91
92
```
92
93
93
94
A function to unmount the test component. This is commonly used to trigger cleanup effects for
94
95
` useEffect ` hooks.
95
96
97
+ ### ` hydrate `
98
+
99
+ ``` ts
100
+ hydrate : () => void
101
+ ```
102
+
103
+ > This is only used when using the ` server ` module. See [ Rendering] ( /renderer ) for more information
104
+
105
+ A function to hydrate the component. This is commonly used before ` act ` calls and after ` rerender `
106
+ calls.
107
+
96
108
### ` ...asyncUtils `
97
109
98
110
Utilities to assist with testing asynchronous behaviour. See the
@@ -102,15 +114,15 @@ Utilities to assist with testing asynchronous behaviour. See the
102
114
103
115
## ` act `
104
116
105
- This is the same [`act` function](https:// reactjs.org/docs/test-utils.html#act) that is exported by
106
- `react-test- renderer` .
117
+ This is the same [ ` act ` function] ( https://reactjs.org/docs/test-utils.html#act ) function that is
118
+ exported from your chosen renderer. Although, they both work the same .
107
119
108
120
---
109
121
110
122
## ` cleanup `
111
123
112
- ```js
113
- function cleanup: Promise<void>
124
+ ``` ts
125
+ cleanup : () => Promise < void >
114
126
```
115
127
116
128
Unmounts any rendered hooks rendered with ` renderHook ` , ensuring all effects have been flushed. Any
@@ -142,7 +154,8 @@ module.exports = {
142
154
```
143
155
144
156
Alternatively, you can change your test to import from ` @testing-library/react-hooks/pure ` instead
145
- of the regular imports.
157
+ of the regular imports. This applys to any of our export methods documented in
158
+ [ Rendering] ( /rendering#being-specific ) .
146
159
147
160
``` diff
148
161
- import { renderHook, cleanup, act } from '@testing-library/react-hooks'
@@ -156,8 +169,8 @@ variable to `true` before importing `@testing-library/react-hooks` will also dis
156
169
157
170
## ` addCleanup `
158
171
159
- ` ` ` js
160
- function addCleanup (callback : function (): void| Promise<void>): function(): void
172
+ ``` ts
173
+ addCleanup : (callback : () => void | Promise <void >) => () => void
161
174
```
162
175
163
176
Add a callback to be called during [ ` cleanup ` ] ( /reference/api#cleanup ) , returning a function to
@@ -173,8 +186,8 @@ be resolved before moving onto the next cleanup callback.
173
186
174
187
## ` removeCleanup `
175
188
176
- ```js
177
- function removeCleanup(callback: function(): void| Promise<void>): void
189
+ ``` ts
190
+ removeCleanup : (callback : () => void | Promise <void >) => void
178
191
```
179
192
180
193
Removes a cleanup callback previously added with [ ` addCleanup ` ] ( /reference/api#addCleanup ) . Once
@@ -187,10 +200,8 @@ removed, the provided callback will no longer execute as part of running
187
200
188
201
### ` waitForNextUpdate `
189
202
190
- ```js
191
- function waitForNextUpdate(options?: {
192
- timeout?: number
193
- }): Promise<void>
203
+ ``` ts
204
+ waitForNextUpdate : (options ? : { timeout? : number }) => Promise < void >
194
205
```
195
206
196
207
Returns a ` Promise ` that resolves the next time the hook renders, commonly when state is updated as
@@ -203,11 +214,11 @@ The maximum amount of time in milliseconds (ms) to wait. By default, no timeout
203
214
### ` waitFor `
204
215
205
216
``` js
206
- function waitFor(callback: function(): boolean| void, options?: {
217
+ waitFor: (callback : () => boolean | void , options?: {
207
218
interval?: number,
208
219
timeout?: number,
209
220
suppressErrors?: boolean
210
- }): Promise<void>
221
+ }) => Promise < void >
211
222
```
212
223
213
224
Returns a ` Promise ` that resolves if the provided callback executes without exception and returns a
@@ -233,11 +244,11 @@ rejected. By default, errors are suppressed for this utility.
233
244
### ` waitForValueToChange `
234
245
235
246
``` js
236
- function waitForValueToChange(selector: function(): any, options?: {
247
+ waitForValueToChange: (selector : () => any, options?: {
237
248
interval?: number,
238
249
timeout?: number,
239
250
suppressErrors?: boolean
240
- }): Promise < void >
251
+ }) => Promise < void >
241
252
```
242
253
243
254
Returns a ` Promise ` that resolves if the value returned from the provided selector changes. It is
0 commit comments