You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/API.md
+21-19
Original file line number
Diff line number
Diff line change
@@ -400,7 +400,7 @@ test('waiting for an Banana to be removed', async () => {
400
400
});
401
401
```
402
402
403
-
This method expects that the element is initally present in the render tree and then is removed from it. If the element is not present when you call this method it throws an error.
403
+
This method expects that the element is initially present in the render tree and then is removed from it. If the element is not present when you call this method it throws an error.
404
404
405
405
You can use any of `getBy`, `getAllBy`, `queryBy` and `queryAllBy` queries for `expectation` parameter.
406
406
@@ -471,10 +471,10 @@ Useful function to help testing components that use hooks API. By default any `r
471
471
Defined as:
472
472
473
473
```ts
474
-
function renderHook(
475
-
callback: (props?:any) =>any,
476
-
options?:RenderHookOptions
477
-
):RenderHookResult;
474
+
function renderHook<Result, Props>(
475
+
callback: (props?:Props) =>Result,
476
+
options?:RenderHookOptions<Props>
477
+
):RenderHookResult<Result, Props>;
478
478
```
479
479
480
480
Renders a test component that will call the provided `callback`, including any hooks it calls, every time it renders. Returns [`RenderHookResult`](#renderhookresult-object) object, which you can interact with.
@@ -515,41 +515,43 @@ The `props` passed into the callback will be the `initialProps` provided in the
515
515
516
516
### `options` (Optional)
517
517
518
-
A `RenderHookOptions` object to modify the execution of the `callback` function, containing the following properties:
518
+
A `RenderHookOptions<Props>` object to modify the execution of the `callback` function, containing the following properties:
519
519
520
520
#### `initialProps`
521
521
522
-
The initial values to pass as `props` to the `callback` function of `renderHook`.
522
+
The initial values to pass as `props` to the `callback` function of `renderHook`. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
523
523
524
524
#### `wrapper`
525
525
526
-
A React component to wrap the test component in when rendering. This is usually used to add context providers from `React.createContext` for the hook to access with `useContext`.`initialProps` and props subsequently set by `rerender` will be provided to the wrapper.
526
+
A React component to wrap the test component in when rendering. This is usually used to add context providers from `React.createContext` for the hook to access with `useContext`.
527
527
528
-
### `RenderHookResult` object
528
+
### `RenderHookResult<Result, Props>` object
529
529
530
530
The `renderHook` function returns an object that has the following properties:
531
531
532
532
#### `result`
533
533
534
534
```jsx
535
535
{
536
-
all:Array<any>
537
-
current: any,
538
-
error:Error
536
+
current: Result
539
537
}
540
538
```
541
539
542
-
The `current` value of the `result` will reflect the latest of whatever is returned from the `callback` passed to `renderHook`. Any thrown values from the latest call will be reflected in the `error` value of the `result`. The `all` value is an array containing all the returns (including the most recent) from the callback. These could be `result` or an `error` depending on what the callback returned at the time.
540
+
The `current` value of the `result` will reflect the latest of whatever is returned from the `callback` passed to `renderHook`. The `Result` type is determined by the type passed to or inferred by the `renderHook` call.
543
541
544
542
#### `rerender`
545
543
546
-
function rerender(newProps?: any): void
544
+
```ts
545
+
function rerender(newProps?:Props):void;
546
+
```
547
547
548
-
A function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders.
548
+
A function to rerender the test component, causing any hooks to be recalculated. If `newProps` are passed, they will replace the `callback` function's `initialProps` for subsequent rerenders. The `Props` type is determined by the type passed to or inferred by the `renderHook` call.
549
549
550
550
#### `unmount`
551
551
552
-
function unmount(): void
552
+
```ts
553
+
function unmount():void;
554
+
```
553
555
554
556
A function to unmount the test component. This is commonly used to trigger cleanup effects for `useEffect` hooks.
555
557
@@ -559,7 +561,7 @@ Here we present some extra examples of using `renderHook` API.
0 commit comments