Skip to content

Commit

Permalink
fix types and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kentcdodds committed Apr 15, 2022
1 parent 55811ff commit 144b485
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,47 @@ export function render(
options?: Omit<RenderOptions, 'queries'>,
): RenderResult

// TODO JSDOC
interface RenderHookResult<Result, Props> {
/**
* Triggers a re-render. The props will be passed to your renderHook callback.
*/
rerender: (props?: Props) => void
result: {current: Result}
/**
* This is a stable reference to the latest value returned by your renderHook
* callback
*/
result: {
/**
* The value returned by your renderHook callback
*/
current: Result
}
/**
* Unmounts the test component. This is useful for when you need to test
* any cleanup your useEffects have.
*/
unmount: () => void
}

// TODO JSDOC
interface RenderHookOptions<Props> {
/**
* The argument passed to the renderHook callback. Can be useful if you plan
* to use the rerender utility to change the values passed to your hook.
*/
initialProps?: Props
wrapper?: React.ComponentType
/**
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
* reusable custom render functions for common data providers. See setup for examples.
*
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
*/
wrapper?: React.JSXElementConstructor<{children: React.ReactElement}>
}

// TODO JSDOC
/**
* Allows you to render a hook within a test React component without having to
* create that component yourself.
*/
export function renderHook<Result, Props>(
render: (initialProps: Props) => Result,
options?: RenderHookOptions<Props>,
Expand Down

0 comments on commit 144b485

Please sign in to comment.