@@ -52,7 +52,7 @@ export type BaseRenderOptions<
5252 BaseElement extends RendererableContainer | HydrateableContainer ,
5353> = RenderOptions < Q , Container , BaseElement >
5454
55- type RendererableContainer = ReactDOMClient . Container
55+ type RendererableContainer = Parameters < typeof ReactDOMClient [ 'createRoot' ] > [ 0 ]
5656type HydrateableContainer = Parameters < typeof ReactDOMClient [ 'hydrateRoot' ] > [ 0 ]
5757/** @deprecated */
5858export interface ClientRenderOptions <
@@ -61,8 +61,8 @@ export interface ClientRenderOptions<
6161 BaseElement extends RendererableContainer = Container ,
6262> extends BaseRenderOptions < Q , Container , BaseElement > {
6363 /**
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.
6666 *
6767 * @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
6868 */
@@ -75,8 +75,8 @@ export interface HydrateOptions<
7575 BaseElement extends HydrateableContainer = Container ,
7676> extends BaseRenderOptions < Q , Container , BaseElement > {
7777 /**
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.
8080 *
8181 * @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
8282 */
@@ -87,10 +87,13 @@ export interface RenderOptions<
8787 Q extends Queries = typeof queries ,
8888 Container extends RendererableContainer | HydrateableContainer = HTMLElement ,
8989 BaseElement extends RendererableContainer | HydrateableContainer = Container ,
90+ LegacyRoot extends boolean = boolean ,
91+ Hydrate extends boolean = boolean ,
9092> {
9193 /**
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.
9497 *
9598 * For example: If you are unit testing a `<tbody>` element, it cannot be a child of a div. In this case, you can
9699 * specify a table as the render container.
@@ -99,38 +102,43 @@ export interface RenderOptions<
99102 */
100103 container ?: Container
101104 /**
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()`.
104107 *
105108 * @see https://testing-library.com/docs/react-testing-library/api/#baseelement
106109 */
107110 baseElement ?: BaseElement
108111 /**
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.
111114 *
112115 * @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
113116 */
114- hydrate ?: boolean
117+ hydrate ?: Hydrate
115118 /**
116119 * Only works if used with React 18.
117120 * Set to `true` if you want to force synchronous `ReactDOM.render`.
118121 * Otherwise `render` will default to concurrent React if available.
119122 */
120- legacyRoot ?: boolean
123+ legacyRoot ?: LegacyRoot
121124 /**
122125 * Queries to bind. Overrides the default set from DOM Testing Library unless merged.
123126 *
124127 * @see https://testing-library.com/docs/react-testing-library/api/#queries
125128 */
126129 queries ?: Q
127130 /**
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.
130133 *
131134 * @see https://testing-library.com/docs/react-testing-library/api/#wrapper
132135 */
133136 wrapper ?: React . JSXElementConstructor < { children : React . ReactNode } >
137+ renderOptions ?: LegacyRoot extends true
138+ ? never
139+ : Hydrate extends true
140+ ? ReactDOMClient . HydrationOptions
141+ : ReactDOMClient . RootOptions
134142}
135143
136144type Omit < T , K extends keyof T > = Pick < T , Exclude < keyof T , K > >
@@ -142,14 +150,12 @@ export function render<
142150 Q extends Queries = typeof queries ,
143151 Container extends RendererableContainer | HydrateableContainer = HTMLElement ,
144152 BaseElement extends RendererableContainer | HydrateableContainer = Container ,
153+ LegacyRoot extends boolean = boolean ,
154+ Hydrate extends boolean = boolean ,
145155> (
146156 ui : React . ReactNode ,
147- options : RenderOptions < Q , Container , BaseElement > ,
157+ options ? : RenderOptions < Q , Container , BaseElement , LegacyRoot , Hydrate > ,
148158) : RenderResult < Q , Container , BaseElement >
149- export function render (
150- ui : React . ReactNode ,
151- options ?: Omit < RenderOptions , 'queries' > ,
152- ) : RenderResult
153159
154160export interface RenderHookResult < Result , Props > {
155161 /**
@@ -189,8 +195,8 @@ export interface ClientRenderHookOptions<
189195 BaseElement extends Element | DocumentFragment = Container ,
190196> extends BaseRenderHookOptions < Props , Q , Container , BaseElement > {
191197 /**
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.
194200 *
195201 * @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
196202 */
@@ -205,8 +211,8 @@ export interface HydrateHookOptions<
205211 BaseElement extends Element | DocumentFragment = Container ,
206212> extends BaseRenderHookOptions < Props , Q , Container , BaseElement > {
207213 /**
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.
210216 *
211217 * @see https://testing-library.com/docs/react-testing-library/api/#hydrate)
212218 */
0 commit comments