mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
[@testing-library/react-hooks] Add cleanup function type (#39900)
* Add cleanup function type * Update version number
This commit is contained in:
+9
-1
@@ -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 <https://github.com/mpeyper>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -24,4 +24,12 @@ export interface RenderHookResult<P, R> {
|
||||
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<P, R>(callback: (props: P) => R, options?: RenderHookOptions<P>): RenderHookResult<P, R>;
|
||||
|
||||
/**
|
||||
* Unmounts any rendered hooks rendered with `renderHook`, ensuring all effects have been flushed.
|
||||
*/
|
||||
export function cleanup(): Promise<void>;
|
||||
|
||||
@@ -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<void>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user