@@ -12,6 +12,7 @@ import {
1212 screen as rtlScreen ,
1313 Screen ,
1414 render as testingLibraryRender ,
15+ RenderOptions as TestingLibraryRenderOptions ,
1516 within ,
1617} from '@testing-library/react/pure' ;
1718import { userEvent } from '@testing-library/user-event' ;
@@ -201,7 +202,7 @@ const customQueries = {
201202 findAllDescriptionsOf,
202203} ;
203204
204- interface RenderConfiguration {
205+ interface RenderConfiguration extends Pick < TestingLibraryRenderOptions , 'reactStrictMode' > {
205206 /**
206207 * https://testing-library.com/docs/react-testing-library/api#container
207208 */
@@ -232,7 +233,7 @@ interface ServerRenderConfiguration extends RenderConfiguration {
232233 container : HTMLElement ;
233234}
234235
235- export type RenderOptions = Partial < RenderConfiguration > ;
236+ export type RenderOptions = Omit < Partial < RenderConfiguration > , 'reactStrictMode' > ;
236237
237238export interface MuiRenderResult extends RenderResult < typeof queries & typeof customQueries > {
238239 user : ReturnType < typeof userEvent . setup > ;
@@ -256,14 +257,15 @@ function render(
256257 element : React . ReactElement < DataAttributes > ,
257258 configuration : ClientRenderConfiguration ,
258259) : MuiRenderResult {
259- const { container, hydrate, wrapper } = configuration ;
260+ const { container, hydrate, wrapper, reactStrictMode } = configuration ;
260261
261262 const testingLibraryRenderResult = traceSync ( 'render' , ( ) =>
262263 testingLibraryRender ( element , {
263264 container,
264265 hydrate,
265266 queries : { ...queries , ...customQueries } ,
266267 wrapper,
268+ reactStrictMode,
267269 } ) ,
268270 ) ;
269271 const result : MuiRenderResult = {
@@ -628,24 +630,16 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
628630 serverContainer = null ! ;
629631 } ) ;
630632
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 ;
637635
638- const usesLegacyRoot = reactMajor < 18 ;
639- const Mode = strict && ( strictEffects || usesLegacyRoot ) ? React . StrictMode : React . Fragment ;
640636 return function Wrapper ( { children } : { children ?: React . ReactNode } ) {
641637 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 >
649643 ) ;
650644 } ;
651645 }
@@ -661,8 +655,14 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende
661655 ) ;
662656 }
663657
658+ const usesLegacyRoot = reactMajor < 18 ;
659+ const reactStrictMode =
660+ ( options . strict ?? globalStrict ) &&
661+ ( ( options . strictEffects ?? globalStrictEffects ) || usesLegacyRoot ) ;
662+
664663 return render ( element , {
665664 ...options ,
665+ reactStrictMode,
666666 hydrate : false ,
667667 wrapper : createWrapper ( options ) ,
668668 } ) ;
0 commit comments