forked from testing-library/react-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
71 lines (59 loc) · 1.78 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {queries, BoundFunction} from 'dom-testing-library'
export * from 'dom-testing-library'
interface Query extends Function {
(container: HTMLElement, ...args: any[]): HTMLElement[] | HTMLElement | null
}
interface Queries {
[T: string]: Query
}
export type RenderResult<Q extends Queries = typeof queries> = {
container: HTMLElement
baseElement: HTMLElement
debug: (baseElement?: HTMLElement | DocumentFragment) => void
rerender: (ui: React.ReactElement<any>) => void
unmount: () => boolean
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction<Q[P]>}
export type HookResult<TResult> = {
result: React.MutableRefObject<TResult>
rerender: () => void
unmount: () => boolean
}
export type HookOptions = {
wrapper: React.FunctionComponent
}
export interface RenderOptions<Q extends Queries = typeof queries> {
container?: HTMLElement
baseElement?: HTMLElement
hydrate?: boolean
queries?: Q
}
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
/**
* Render into a container which is appended to document.body. It should be used with cleanup.
*/
export function render(
ui: React.ReactElement<any>,
options?: Omit<RenderOptions, 'queries'>,
): RenderResult
export function render<Q extends Queries>(
ui: React.ReactElement<any>,
options: RenderOptions<Q>,
): RenderResult<Q>
/**
* Renders a test component that calls back to the test.
*/
export function testHook<T>(
callback: () => T,
options?: Partial<HookOptions>,
): HookResult<T>
/**
* Unmounts React trees that were mounted with render.
*/
export function cleanup(): void
/**
* Simply calls ReactDOMTestUtils.act(cb)
* If that's not available (older version of react) then it
* simply calls the given callback immediately
*/
export function act(callback: () => void): void