1
- import type { ReactTestInstance , ReactTestRenderer } from 'react-test-renderer' ;
1
+ import type {
2
+ ReactTestInstance ,
3
+ ReactTestRenderer ,
4
+ TestRendererOptions ,
5
+ } from 'react-test-renderer' ;
2
6
import * as React from 'react' ;
3
7
import { Profiler } from 'react' ;
4
8
import act from './act' ;
@@ -14,7 +18,19 @@ import { setRenderResult } from './screen';
14
18
import { getQueriesForElement } from './within' ;
15
19
16
20
export interface RenderOptions {
21
+ /**
22
+ * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
23
+ * reusable custom render functions for common data providers.
24
+ */
17
25
wrapper ?: React . ComponentType < any > ;
26
+
27
+ /**
28
+ * Only works if used with React 18.
29
+ * Set to `true` if you want to force synchronous rendering.
30
+ * Otherwise `render` will default to concurrent React if available.
31
+ */
32
+ legacyRoot ?: boolean | undefined ;
33
+
18
34
createNodeMock ?: ( element : React . ReactElement ) => unknown ;
19
35
unstable_validateStringsRenderedWithinText ?: boolean ;
20
36
}
@@ -39,11 +55,18 @@ export function renderInternal<T>(
39
55
) {
40
56
const {
41
57
wrapper : Wrapper ,
58
+ legacyRoot,
42
59
detectHostComponentNames = true ,
43
60
unstable_validateStringsRenderedWithinText,
44
- ...testRendererOptions
61
+ ...rest
45
62
} = options || { } ;
46
63
64
+ const testRendererOptions : TestRendererOptions = {
65
+ // @ts -expect-error incomplete typing on RTR package
66
+ unstable_isConcurrent : ! ( legacyRoot ?? getConfig ( ) . legacyRoot ) ,
67
+ ...rest ,
68
+ } ;
69
+
47
70
if ( detectHostComponentNames ) {
48
71
configureHostComponentNamesIfNeeded ( ) ;
49
72
}
0 commit comments