From 05193ce4f9547240857af3e6f261b8523f97ff21 Mon Sep 17 00:00:00 2001 From: eps1lon Date: Mon, 15 Nov 2021 19:10:01 +0100 Subject: [PATCH] Add types --- types/index.d.ts | 19 +++++++++++++++++++ types/test.tsx | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index b4386996..fed00d67 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -95,6 +95,25 @@ export function render( options?: Omit, ): RenderResult +// TODO JSDOC +interface RenderHookResult { + rerender: (props?: Props) => void + result: { current: Result } + unmount: () => void +} + +// TODO JSDOC +interface RenderHookOptions { + initialProps?: Props + wrapper?: React.ComponentType +} + +// TODO JSDOC +export function renderHook( + render: (initialProps?: Props) => Result, + options?: RenderHookOptions, +): RenderHookResult + /** * Unmounts React trees that were mounted with render. */ diff --git a/types/test.tsx b/types/test.tsx index 239caed6..931f3b33 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import {render, fireEvent, screen, waitFor} from '.' +import {render, fireEvent, screen, waitFor, renderHook} from '.' import * as pure from './pure' export async function testRender() { @@ -100,6 +100,16 @@ export function testQueries() { ) } +export function testRenderHook() { + const {result, rerender, unmount} = renderHook(() => React.useState(2)[0]) + + expectType(result.current) + + rerender() + + unmount() +} + /* eslint testing-library/prefer-explicit-assert: "off",