name | route |
---|---|
API Reference |
/reference/api |
react-hooks-testing-library
exports the following methods:
function renderHook(
callback: function(props?: any): any,
options?: RenderHookOptions
): RenderHookResult
Renders a test component that will call the provided callback
, including any hooks it calls, every
time it renders.
The renderHook
function accept the following arguments:
The function that is called each render
of the test component. This function should call one or
more hooks for testing.
The props
passed into the callback will be the initialProps
provided in the options
to
renderHook
, unless new props are provided by a subsequent rerender
call.
An options object to modify the execution of the callback
function. See the
renderHook
Options section for more details.
The renderHook
function accepts the following options as the second parameter:
The initial values to pass as props
to the callback
function of `renderHook.
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
.
The renderHook
method returns an object that has a following properties:
{
current: any,
error: Error
}
The current
value or the result
will reflect whatever is returned from the callback
passed to
renderHook
. Any thrown values will be reflected in the error
value of the result
.
function waitForNextUpdate(): Promise<void>
waitForNextUpdate
(function
) - returns aPromise
that resolves the next time the hook renders, commonly when state is updated as the result of a asynchronous action
function rerender(newProps?: any): void
A function to rerender the test component, causing any hooks to be recalculated. If newProps
are
passed, the will replace the initialProps
passed to the callback
function for the rerender any
subsequent renders.
function unmount(): void
A function to unmount the test component. This is commonly used to trigger cleanup effects for
useEffect
hooks.
This is the same act
function that is exported by
react-test-renderer
.