1 |
|
2 |
|
3 | import {
|
4 | queries,
|
5 | Queries,
|
6 | BoundFunction,
|
7 | prettyFormat,
|
8 | } from '@testing-library/dom'
|
9 | import {Renderer} from 'react-dom'
|
10 | import {act as reactAct} from 'react-dom/test-utils'
|
11 |
|
12 | export * from '@testing-library/dom'
|
13 |
|
14 | export type RenderResult<
|
15 | Q extends Queries = typeof queries,
|
16 | Container extends Element | DocumentFragment = HTMLElement,
|
17 | BaseElement extends Element | DocumentFragment = Container,
|
18 | > = {
|
19 | container: Container
|
20 | baseElement: BaseElement
|
21 | debug: (
|
22 | baseElement?:
|
23 | | Element
|
24 | | DocumentFragment
|
25 | | Array<Element | DocumentFragment>,
|
26 | maxLength?: number,
|
27 | options?: prettyFormat.OptionsReceived,
|
28 | ) => void
|
29 | rerender: (ui: React.ReactElement) => void
|
30 | unmount: () => void
|
31 | asFragment: () => DocumentFragment
|
32 | } & {[P in keyof Q]: BoundFunction<Q[P]>}
|
33 |
|
34 | export interface RenderOptions<
|
35 | Q extends Queries = typeof queries,
|
36 | Container extends Element | DocumentFragment = HTMLElement,
|
37 | BaseElement extends Element | DocumentFragment = Container,
|
38 | > {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | container?: Container
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | baseElement?: BaseElement
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | hydrate?: boolean
|
63 | |
64 |
|
65 |
|
66 |
|
67 | legacyRoot?: boolean
|
68 | |
69 |
|
70 |
|
71 |
|
72 |
|
73 | queries?: Q
|
74 | |
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | wrapper?: React.JSXElementConstructor<{children: React.ReactElement}>
|
81 | }
|
82 |
|
83 | type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | export function render<
|
89 | Q extends Queries = typeof queries,
|
90 | Container extends Element | DocumentFragment = HTMLElement,
|
91 | BaseElement extends Element | DocumentFragment = Container,
|
92 | >(
|
93 | ui: React.ReactElement,
|
94 | options: RenderOptions<Q, Container, BaseElement>,
|
95 | ): RenderResult<Q, Container, BaseElement>
|
96 | export function render(
|
97 | ui: React.ReactElement,
|
98 | options?: Omit<RenderOptions, 'queries'>,
|
99 | ): RenderResult
|
100 |
|
101 | export interface RenderHookResult<Result, Props> {
|
102 | /**
|
103 | * Triggers a re-render. The props will be passed to your renderHook callback.
|
104 | */
|
105 | rerender: (props?: Props) => void
|
106 | /**
|
107 | * This is a stable reference to the latest value returned by your renderHook
|
108 | * callback
|
109 | */
|
110 | result: {
|
111 | |
112 |
|
113 |
|
114 | current: Result
|
115 | }
|
116 | |
117 |
|
118 |
|
119 |
|
120 | unmount: () => void
|
121 | }
|
122 |
|
123 | export interface RenderHookOptions<
|
124 | Props,
|
125 | Q extends Queries = typeof queries,
|
126 | Container extends Element | DocumentFragment = HTMLElement,
|
127 | BaseElement extends Element | DocumentFragment = Container,
|
128 | > extends RenderOptions<Q, Container, BaseElement> {
|
129 | |
130 |
|
131 |
|
132 |
|
133 | initialProps?: Props
|
134 | }
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | export function renderHook<
|
141 | Result,
|
142 | Props,
|
143 | Q extends Queries = typeof queries,
|
144 | Container extends Element | DocumentFragment = HTMLElement,
|
145 | BaseElement extends Element | DocumentFragment = Container,
|
146 | >(
|
147 | render: (initialProps: Props) => Result,
|
148 | options?: RenderHookOptions<Props, Q, Container, BaseElement>,
|
149 | ): RenderHookResult<Result, Props>
|
150 |
|
151 | /**
|
152 | * Unmounts React trees that were mounted with render.
|
153 | */
|
154 | export function cleanup(): void
|
155 |
|
156 | /**
|
157 | * Simply calls ReactDOMTestUtils.act(cb)
|
158 | * If that's not available (older version of react) then it
|
159 | * simply calls the given callback immediately
|
160 | */
|
161 | export const act: typeof reactAct extends undefined
|
162 | ? (callback: () => void) => void
|
163 | : typeof reactAct
|
164 |
|
\ | No newline at end of file |