Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 15, 2021
1 parent 0f93c98 commit 05193ce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions types/index.d.ts
Expand Up @@ -95,6 +95,25 @@ export function render(
options?: Omit<RenderOptions, 'queries'>,
): RenderResult

// TODO JSDOC
interface RenderHookResult<Result, Props> {
rerender: (props?: Props) => void
result: { current: Result }
unmount: () => void
}

// TODO JSDOC
interface RenderHookOptions<Props> {
initialProps?: Props
wrapper?: React.ComponentType
}

// TODO JSDOC
export function renderHook<Result, Props>(
render: (initialProps?: Props) => Result,
options?: RenderHookOptions<Props>,
): RenderHookResult<Result, Props>

/**
* Unmounts React trees that were mounted with render.
*/
Expand Down
12 changes: 11 additions & 1 deletion 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() {
Expand Down Expand Up @@ -100,6 +100,16 @@ export function testQueries() {
)
}

export function testRenderHook() {
const {result, rerender, unmount} = renderHook(() => React.useState(2)[0])

expectType<number, typeof result.current>(result.current)

rerender()

unmount()
}

/*
eslint
testing-library/prefer-explicit-assert: "off",
Expand Down

0 comments on commit 05193ce

Please sign in to comment.