Skip to content

Commit 8436c7e

Browse files
AndrewmatKent C. Dodds
authored and
Kent C. Dodds
committed
fix(TS): typing of testHook (#292)
* Adds typing for testHook return * Adds typings section to contributing.md
1 parent 9c606da commit 8436c7e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ inside:
5858
pre-commit
5959
```
6060

61+
### Add typings
62+
63+
If your PR introduced some changes in the API, you are more than welcome to
64+
modify the Typescript type definition to reflect those changes. Just modify the
65+
`/typings/index.d.ts` file accordingly. If you have never seen Typescript
66+
definitions before, you can read more about it in its
67+
[documentation pages](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html)
68+
6169
## Help needed
6270

6371
Please checkout the [the open issues][issues]

typings/index.d.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export type RenderResult<Q extends Queries = typeof queries> = {
1919
asFragment: () => DocumentFragment
2020
} & {[P in keyof Q]: BoundFunction<Q[P]>}
2121

22+
export type HookResult = {
23+
rerender: () => void
24+
unmount: () => boolean
25+
}
26+
2227
export interface RenderOptions<Q extends Queries = typeof queries> {
2328
container?: HTMLElement
2429
baseElement?: HTMLElement
@@ -43,7 +48,7 @@ export function render<Q extends Queries>(
4348
/**
4449
* Renders a test component that calls back to the test.
4550
*/
46-
export function testHook(callback: () => void): void
51+
export function testHook(callback: () => void): HookResult
4752

4853
/**
4954
* Unmounts React trees that were mounted with render.

0 commit comments

Comments
 (0)