diff --git a/types/testing-library__react-hooks/index.d.ts b/types/testing-library__react-hooks/index.d.ts index 092dd12951..3e273488b8 100644 --- a/types/testing-library__react-hooks/index.d.ts +++ b/types/testing-library__react-hooks/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for @testing-library/react-hooks 2.0 +// Type definitions for @testing-library/react-hooks 3.1 // Project: https://github.com/testing-library/react-hooks-testing-library // Definitions by: Michael Peyper // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -24,4 +24,12 @@ export interface RenderHookResult { readonly rerender: (newProps?: P) => void; } +/** + * Renders a test component that will call the provided `callback`, including any hooks it calls, every time it renders. + */ export function renderHook(callback: (props: P) => R, options?: RenderHookOptions

): RenderHookResult; + +/** + * Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed. + */ +export function cleanup(): Promise; diff --git a/types/testing-library__react-hooks/testing-library__react-hooks-tests.ts b/types/testing-library__react-hooks/testing-library__react-hooks-tests.ts index 3e990ad04a..958ddf2c89 100644 --- a/types/testing-library__react-hooks/testing-library__react-hooks-tests.ts +++ b/types/testing-library__react-hooks/testing-library__react-hooks-tests.ts @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { renderHook, act } from '@testing-library/react-hooks'; +import { renderHook, act, cleanup } from '@testing-library/react-hooks'; const useHook = (initialValue: number) => { const [value, setValue] = useState(initialValue); @@ -69,3 +69,7 @@ function checkTypesWithVoidResult() { function checkTypesWithPromiseResult() { act(() => Promise.resolve()); } + +function checkTypesForCleanup() { + cleanup(); // $ExpectType Promise +}