[@testing-library/react-hooks] Add cleanup function type (#39900)

* Add cleanup function type

* Update version number
This commit is contained in:
Martin V
2019-10-29 15:24:49 -07:00
committed by Jesse Trinity
parent d83bae23a3
commit c47e5dbbb4
2 changed files with 14 additions and 2 deletions
+9 -1
View File
@@ -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>
}