1
1
/* eslint-disable react/prefer-stateless-function */
2
2
import * as React from 'react' ;
3
- import * as ReactDOM from 'react-dom' ;
4
3
import { expect } from 'chai' ;
5
4
import PropTypes from 'prop-types' ;
5
+ import { createRenderer , waitFor } from '@mui-internal/test-utils' ;
6
6
import elementAcceptingRef from './elementAcceptingRef' ;
7
7
8
8
describe ( 'elementAcceptingRef' , ( ) => {
9
+ const { render } = createRenderer ( ) ;
10
+
9
11
function checkPropType ( element : any , required = false ) {
10
12
PropTypes . checkPropTypes (
11
13
{ children : required ? elementAcceptingRef . isRequired : elementAcceptingRef } ,
@@ -20,35 +22,17 @@ describe('elementAcceptingRef', () => {
20
22
} ) ;
21
23
22
24
describe ( 'acceptance when not required' , ( ) => {
23
- let rootNode : HTMLElement ;
24
-
25
25
function assertPass ( element : any , { shouldMount = true } = { } ) {
26
26
function testAct ( ) {
27
27
checkPropType ( element ) ;
28
28
if ( shouldMount ) {
29
- // TODO: replace with React 18 implementation after https://github.com/testing-library/react-testing-library/issues/1216 is closed.
30
- // eslint-disable-next-line react/no-deprecated
31
- ReactDOM . render (
32
- < React . Suspense fallback = { < p /> } >
33
- { React . cloneElement ( element , { ref : React . createRef ( ) } ) }
34
- </ React . Suspense > ,
35
- rootNode ,
36
- ) ;
29
+ render ( React . cloneElement ( element , { ref : React . createRef ( ) } ) ) ;
37
30
}
38
31
}
39
32
40
33
expect ( testAct ) . not . toErrorDev ( ) ;
41
34
}
42
35
43
- before ( ( ) => {
44
- rootNode = document . createElement ( 'div' ) ;
45
- } ) ;
46
-
47
- afterEach ( ( ) => {
48
- // eslint-disable-next-line react/no-deprecated
49
- ReactDOM . unmountComponentAtNode ( rootNode ) ;
50
- } ) ;
51
-
52
36
it ( 'accepts nully values' , ( ) => {
53
37
assertPass ( undefined , { shouldMount : false } ) ;
54
38
assertPass ( null , { shouldMount : false } ) ;
@@ -90,14 +74,25 @@ describe('elementAcceptingRef', () => {
90
74
assertPass ( < Component /> ) ;
91
75
} ) ;
92
76
93
- it ( 'accepts lazy' , ( ) => {
77
+ it ( 'accepts lazy' , async ( ) => {
94
78
const Component = React . lazy ( ( ) =>
95
79
Promise . resolve ( {
96
80
default : React . forwardRef ( ( props , ref ) => < div { ...props } ref = { ref } /> ) ,
97
81
} ) ,
98
82
) ;
99
83
100
- assertPass ( < Component /> ) ;
84
+ function testAct ( ) {
85
+ checkPropType ( < Component /> ) ;
86
+ render (
87
+ < React . Suspense fallback = { < p /> } >
88
+ { React . cloneElement ( < Component /> , { ref : React . createRef ( ) } ) }
89
+ </ React . Suspense > ,
90
+ ) ;
91
+ }
92
+
93
+ await waitFor ( ( ) => {
94
+ expect ( testAct ) . not . toErrorDev ( ) ;
95
+ } ) ;
101
96
} ) ;
102
97
103
98
it ( 'technically allows other exotics like strict mode' , ( ) => {
0 commit comments