Skip to content

Commit 3d81844

Browse files
committed
Add types
1 parent 0f93c98 commit 3d81844

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

types/index.d.ts

+19
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ export function render(
9595
options?: Omit<RenderOptions, 'queries'>,
9696
): RenderResult
9797

98+
// TODO JSDOC
99+
interface RenderHookResult<Result, Props> {
100+
rerender: (props?: Props) => void
101+
result: {current: Result}
102+
unmount: () => void
103+
}
104+
105+
// TODO JSDOC
106+
interface RenderHookOptions<Props> {
107+
initialProps?: Props
108+
wrapper?: React.ComponentType
109+
}
110+
111+
// TODO JSDOC
112+
export function renderHook<Result, Props>(
113+
render: (initialProps?: Props) => Result,
114+
options?: RenderHookOptions<Props>,
115+
): RenderHookResult<Result, Props>
116+
98117
/**
99118
* Unmounts React trees that were mounted with render.
100119
*/

types/test.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import {render, fireEvent, screen, waitFor} from '.'
2+
import {render, fireEvent, screen, waitFor, renderHook} from '.'
33
import * as pure from './pure'
44

55
export async function testRender() {
@@ -100,6 +100,16 @@ export function testQueries() {
100100
)
101101
}
102102

103+
export function testRenderHook() {
104+
const {result, rerender, unmount} = renderHook(() => React.useState(2)[0])
105+
106+
expectType<number, typeof result.current>(result.current)
107+
108+
rerender()
109+
110+
unmount()
111+
}
112+
103113
/*
104114
eslint
105115
testing-library/prefer-explicit-assert: "off",

0 commit comments

Comments
 (0)