@@ -52,7 +52,7 @@ export type BaseRenderOptions<
52
52
BaseElement extends RendererableContainer | HydrateableContainer ,
53
53
> = RenderOptions < Q , Container , BaseElement >
54
54
55
- type RendererableContainer = ReactDOMClient . Container
55
+ type RendererableContainer = Parameters < typeof ReactDOMClient [ 'createRoot' ] > [ 0 ]
56
56
type HydrateableContainer = Parameters < typeof ReactDOMClient [ 'hydrateRoot' ] > [ 0 ]
57
57
/** @deprecated */
58
58
export interface ClientRenderOptions <
@@ -61,8 +61,8 @@ export interface ClientRenderOptions<
61
61
BaseElement extends RendererableContainer = Container ,
62
62
> extends BaseRenderOptions < Q , Container , BaseElement > {
63
63
/**
64
- * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
65
- * rendering and use ReactDOM.hydrate to mount your components.
64
+ * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using
65
+ * server-side rendering and use ReactDOM.hydrate to mount your components.
66
66
*
67
67
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
68
68
*/
@@ -75,8 +75,8 @@ export interface HydrateOptions<
75
75
BaseElement extends HydrateableContainer = Container ,
76
76
> extends BaseRenderOptions < Q , Container , BaseElement > {
77
77
/**
78
- * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
79
- * rendering and use ReactDOM.hydrate to mount your components.
78
+ * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using
79
+ * server-side rendering and use ReactDOM.hydrate to mount your components.
80
80
*
81
81
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
82
82
*/
@@ -87,10 +87,13 @@ export interface RenderOptions<
87
87
Q extends Queries = typeof queries ,
88
88
Container extends RendererableContainer | HydrateableContainer = HTMLElement ,
89
89
BaseElement extends RendererableContainer | HydrateableContainer = Container ,
90
+ LegacyRoot extends boolean = boolean ,
91
+ Hydrate extends boolean = boolean ,
90
92
> {
91
93
/**
92
- * 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,
93
- * it will not be appended to the document.body automatically.
94
+ * By default, React Testing Library will create a div and append that div to the document.body. Your React component
95
+ * will be rendered in the created div. If you provide your own HTMLElement container via this option, it will not be
96
+ * appended to the document.body automatically.
94
97
*
95
98
* For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can
96
99
* specify a table as the render container.
@@ -99,38 +102,43 @@ export interface RenderOptions<
99
102
*/
100
103
container ?: Container
101
104
/**
102
- * Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This is used as
103
- * the base element for the queries as well as what is printed when you use `debug()`.
105
+ * Defaults to the container if the container is specified. Otherwise `document.body` is used for the default. This
106
+ * is used as the base element for the queries as well as what is printed when you use `debug()`.
104
107
*
105
108
* @see https://testing-library.com/docs/react-testing-library/api/#baseelement
106
109
*/
107
110
baseElement ?: BaseElement
108
111
/**
109
- * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
110
- * rendering and use ReactDOM.hydrate to mount your components.
112
+ * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using
113
+ * server-side rendering and use ReactDOM.hydrate to mount your components.
111
114
*
112
115
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
113
116
*/
114
- hydrate ?: boolean
117
+ hydrate ?: Hydrate
115
118
/**
116
119
* Only works if used with React 18.
117
120
* Set to `true` if you want to force synchronous `ReactDOM.render`.
118
121
* Otherwise `render` will default to concurrent React if available.
119
122
*/
120
- legacyRoot ?: boolean
123
+ legacyRoot ?: LegacyRoot
121
124
/**
122
125
* Queries to bind. Overrides the default set from DOM Testing Library unless merged.
123
126
*
124
127
* @see https://testing-library.com/docs/react-testing-library/api/#queries
125
128
*/
126
129
queries ?: Q
127
130
/**
128
- * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
129
- * reusable custom render functions for common data providers. See setup for examples.
131
+ * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for
132
+ * creating reusable custom render functions for common data providers. See setup for examples.
130
133
*
131
134
* @see https://testing-library.com/docs/react-testing-library/api/#wrapper
132
135
*/
133
136
wrapper ?: React . JSXElementConstructor < { children : React . ReactNode } >
137
+ renderOptions ?: LegacyRoot extends true
138
+ ? never
139
+ : Hydrate extends true
140
+ ? ReactDOMClient . HydrationOptions
141
+ : ReactDOMClient . RootOptions
134
142
}
135
143
136
144
type Omit < T , K extends keyof T > = Pick < T , Exclude < keyof T , K > >
@@ -142,14 +150,12 @@ export function render<
142
150
Q extends Queries = typeof queries ,
143
151
Container extends RendererableContainer | HydrateableContainer = HTMLElement ,
144
152
BaseElement extends RendererableContainer | HydrateableContainer = Container ,
153
+ LegacyRoot extends boolean = boolean ,
154
+ Hydrate extends boolean = boolean ,
145
155
> (
146
156
ui : React . ReactNode ,
147
- options : RenderOptions < Q , Container , BaseElement > ,
157
+ options ? : RenderOptions < Q , Container , BaseElement , LegacyRoot , Hydrate > ,
148
158
) : RenderResult < Q , Container , BaseElement >
149
- export function render (
150
- ui : React . ReactNode ,
151
- options ?: Omit < RenderOptions , 'queries' > ,
152
- ) : RenderResult
153
159
154
160
export interface RenderHookResult < Result , Props > {
155
161
/**
@@ -189,8 +195,8 @@ export interface ClientRenderHookOptions<
189
195
BaseElement extends Element | DocumentFragment = Container ,
190
196
> extends BaseRenderHookOptions < Props , Q , Container , BaseElement > {
191
197
/**
192
- * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
193
- * rendering and use ReactDOM.hydrate to mount your components.
198
+ * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using
199
+ * server-side rendering and use ReactDOM.hydrate to mount your components.
194
200
*
195
201
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
196
202
*/
@@ -205,8 +211,8 @@ export interface HydrateHookOptions<
205
211
BaseElement extends Element | DocumentFragment = Container ,
206
212
> extends BaseRenderHookOptions < Props , Q , Container , BaseElement > {
207
213
/**
208
- * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using server-side
209
- * rendering and use ReactDOM.hydrate to mount your components.
214
+ * If `hydrate` is set to `true`, then it will render with `ReactDOM.hydrate`. This may be useful if you are using
215
+ * server-side rendering and use ReactDOM.hydrate to mount your components.
210
216
*
211
217
* @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
212
218
*/
0 commit comments