@@ -12,6 +12,7 @@ import {
12
12
screen as rtlScreen ,
13
13
Screen ,
14
14
render as testingLibraryRender ,
15
+ RenderOptions as TestingLibraryRenderOptions ,
15
16
within ,
16
17
} from '@testing-library/react/pure' ;
17
18
import { userEvent } from '@testing-library/user-event' ;
@@ -201,7 +202,7 @@ const customQueries = {
201
202
findAllDescriptionsOf,
202
203
} ;
203
204
204
- interface RenderConfiguration {
205
+ interface RenderConfiguration extends Pick < TestingLibraryRenderOptions , 'reactStrictMode' > {
205
206
/**
206
207
* https://testing-library.com/docs/react-testing-library/api#container
207
208
*/
@@ -232,7 +233,7 @@ interface ServerRenderConfiguration extends RenderConfiguration {
232
233
container : HTMLElement ;
233
234
}
234
235
235
- export type RenderOptions = Partial < RenderConfiguration > ;
236
+ export type RenderOptions = Omit < Partial < RenderConfiguration > , 'reactStrictMode' > ;
236
237
237
238
export interface MuiRenderResult extends RenderResult < typeof queries & typeof customQueries > {
238
239
user : ReturnType < typeof userEvent . setup > ;
@@ -256,14 +257,15 @@ function render(
256
257
element : React . ReactElement < DataAttributes > ,
257
258
configuration : ClientRenderConfiguration ,
258
259
) : MuiRenderResult {
259
- const { container, hydrate, wrapper } = configuration ;
260
+ const { container, hydrate, wrapper, reactStrictMode } = configuration ;
260
261
261
262
const testingLibraryRenderResult = traceSync ( 'render' , ( ) =>
262
263
testingLibraryRender ( element , {
263
264
container,
264
265
hydrate,
265
266
queries : { ...queries , ...customQueries } ,
266
267
wrapper,
268
+ reactStrictMode,
267
269
} ) ,
268
270
) ;
269
271
const result : MuiRenderResult = {
@@ -628,24 +630,16 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
628
630
serverContainer = null ! ;
629
631
} ) ;
630
632
631
- function createWrapper ( options : Partial < RenderConfiguration > ) {
632
- const {
633
- strict = globalStrict ,
634
- strictEffects = globalStrictEffects ,
635
- wrapper : InnerWrapper = React . Fragment ,
636
- } = options ;
633
+ function createWrapper ( options : Pick < RenderOptions , 'wrapper' > ) {
634
+ const { wrapper : InnerWrapper = React . Fragment } = options ;
637
635
638
- const usesLegacyRoot = reactMajor < 18 ;
639
- const Mode = strict && ( strictEffects || usesLegacyRoot ) ? React . StrictMode : React . Fragment ;
640
636
return function Wrapper ( { children } : { children ?: React . ReactNode } ) {
641
637
return (
642
- < Mode >
643
- < EmotionCacheProvider value = { emotionCache } >
644
- < React . Profiler id = { profiler . id } onRender = { profiler . onRender } >
645
- < InnerWrapper > { children } </ InnerWrapper >
646
- </ React . Profiler >
647
- </ EmotionCacheProvider >
648
- </ Mode >
638
+ < EmotionCacheProvider value = { emotionCache } >
639
+ < React . Profiler id = { profiler . id } onRender = { profiler . onRender } >
640
+ < InnerWrapper > { children } </ InnerWrapper >
641
+ </ React . Profiler >
642
+ </ EmotionCacheProvider >
649
643
) ;
650
644
} ;
651
645
}
@@ -661,8 +655,14 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
661
655
) ;
662
656
}
663
657
658
+ const usesLegacyRoot = reactMajor < 18 ;
659
+ const reactStrictMode =
660
+ ( options . strict ?? globalStrict ) &&
661
+ ( ( options . strictEffects ?? globalStrictEffects ) || usesLegacyRoot ) ;
662
+
664
663
return render ( element , {
665
664
...options ,
665
+ reactStrictMode,
666
666
hydrate : false ,
667
667
wrapper : createWrapper ( options ) ,
668
668
} ) ;
0 commit comments