forked from testing-library/react-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.d.ts
124 lines (113 loc) · 3.92 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// TypeScript Version: 3.8
import {
queries,
Queries,
BoundFunction,
prettyFormat,
} from '@testing-library/dom'
import {Renderer} from 'react-dom'
import {act as reactAct} from 'react-dom/test-utils'
export * from '@testing-library/dom'
export type RenderResult<
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement,
> = {
container: Container
baseElement: Element
debug: (
baseElement?:
| Element
| DocumentFragment
| Array<Element | DocumentFragment>,
maxLength?: number,
options?: prettyFormat.OptionsReceived,
) => void
rerender: (ui: React.ReactElement) => void
unmount: () => void
asFragment: () => DocumentFragment
} & {[P in keyof Q]: BoundFunction<Q[P]>}
export interface RenderOptions<
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement,
> {
/**
* By default, React Testing Library will create a div and append that div to the document.body. Your React component will be rendered in the created div. If you provide your own HTMLElement container via this option,
* it will not be appended to the document.body automatically.
*
* For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can
* specify a table as the render container.
*
* @see https://testing-library.com/docs/react-testing-library/api/#container
*/
container?: Container
/**
* Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as
* the base element for the queries as well as what is printed when you use `debug()`.
*
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
*/
baseElement?: Element
/**
* If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
* rendering and use ReactDOM.hydrate to mount your components.
*
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
*/
hydrate?: boolean
/**
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
*
* @see https://testing-library.com/docs/react-testing-library/api/#queries
*/
queries?: Q
/**
* Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
* reusable custom render functions for common data providers. See setup for examples.
*
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
*/
wrapper?: React.JSXElementConstructor<{children: React.ReactElement}>
}
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<
Q extends Queries = typeof queries,
Container extends Element | DocumentFragment = HTMLElement,
>(
ui: React.ReactElement,
options: RenderOptions<Q, Container>,
): RenderResult<Q, Container>
export function render(
ui: React.ReactElement,
options?: Omit<RenderOptions, 'queries'>,
): RenderResult
// TODO JSDOC
interface RenderHookResult<Result, Props> {
rerender: (props?: Props) => void
result: {current: Result}
unmount: () => void
}
// TODO JSDOC
interface RenderHookOptions<Props> {
initialProps?: Props
wrapper?: React.ComponentType
}
// TODO JSDOC
export function renderHook<Result, Props>(
render: (initialProps: Props) => Result,
options?: RenderHookOptions<Props>,
): RenderHookResult<Result, Props>
/**
* 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 const act: typeof reactAct extends undefined
? (callback: () => void) => void
: typeof reactAct