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,94 +22,83 @@ describe('elementAcceptingRef', () => {
20
22
} ) ;
21
23
22
24
describe ( 'acceptance when not required' , ( ) => {
23
- let rootNode : HTMLElement ;
24
-
25
- function assertPass ( element : any , { shouldMount = true } = { } ) {
25
+ async function assertPass ( element : any , { shouldMount = true } = { } ) {
26
26
function testAct ( ) {
27
27
checkPropType ( element ) ;
28
28
if ( shouldMount ) {
29
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 (
30
+ render (
32
31
< React . Suspense fallback = { < p /> } >
33
32
{ React . cloneElement ( element , { ref : React . createRef ( ) } ) }
34
33
</ React . Suspense > ,
35
- rootNode ,
36
34
) ;
37
35
}
38
36
}
39
37
40
- expect ( testAct ) . not . toErrorDev ( ) ;
38
+ await waitFor ( ( ) => {
39
+ expect ( testAct ) . not . toErrorDev ( ) ;
40
+ } ) ;
41
41
}
42
42
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
- it ( 'accepts nully values' , ( ) => {
53
- assertPass ( undefined , { shouldMount : false } ) ;
54
- assertPass ( null , { shouldMount : false } ) ;
43
+ it ( 'accepts nully values' , async ( ) => {
44
+ await assertPass ( undefined , { shouldMount : false } ) ;
45
+ await assertPass ( null , { shouldMount : false } ) ;
55
46
} ) ;
56
47
57
- it ( 'accepts host components' , ( ) => {
58
- assertPass ( < div /> ) ;
48
+ it ( 'accepts host components' , async ( ) => {
49
+ await assertPass ( < div /> ) ;
59
50
} ) ;
60
51
61
- it ( 'class components' , ( ) => {
52
+ it ( 'class components' , async ( ) => {
62
53
class Component extends React . Component {
63
54
render ( ) {
64
55
return null ;
65
56
}
66
57
}
67
58
68
- assertPass ( < Component /> ) ;
59
+ await assertPass ( < Component /> ) ;
69
60
} ) ;
70
61
71
- it ( 'accepts pure class components' , ( ) => {
62
+ it ( 'accepts pure class components' , async ( ) => {
72
63
class Component extends React . PureComponent {
73
64
render ( ) {
74
65
return null ;
75
66
}
76
67
}
77
68
78
- assertPass ( < Component /> ) ;
69
+ await assertPass ( < Component /> ) ;
79
70
} ) ;
80
71
81
- it ( 'accepts forwardRef' , ( ) => {
72
+ it ( 'accepts forwardRef' , async ( ) => {
82
73
const Component = React . forwardRef ( ( ) => null ) ;
83
74
84
- assertPass ( < Component /> ) ;
75
+ await assertPass ( < Component /> ) ;
85
76
} ) ;
86
77
87
- it ( 'accepts memo' , ( ) => {
78
+ it ( 'accepts memo' , async ( ) => {
88
79
const Component = React . memo ( React . forwardRef ( ( ) => null ) ) ;
89
80
90
- assertPass ( < Component /> ) ;
81
+ await assertPass ( < Component /> ) ;
91
82
} ) ;
92
83
93
- it ( 'accepts lazy' , ( ) => {
84
+ it ( 'accepts lazy' , async ( ) => {
94
85
const Component = React . lazy ( ( ) =>
95
86
Promise . resolve ( {
96
87
default : React . forwardRef ( ( props , ref ) => < div { ...props } ref = { ref } /> ) ,
97
88
} ) ,
98
89
) ;
99
90
100
- assertPass ( < Component /> ) ;
91
+ await assertPass ( < Component /> ) ;
101
92
} ) ;
102
93
103
- it ( 'technically allows other exotics like strict mode' , ( ) => {
104
- assertPass ( < React . StrictMode /> ) ;
94
+ it ( 'technically allows other exotics like strict mode' , async ( ) => {
95
+ await assertPass ( < React . StrictMode /> ) ;
105
96
} ) ;
106
97
107
98
// undesired behavior
108
- it ( 'accepts Fragment' , ( ) => {
99
+ it ( 'accepts Fragment' , async ( ) => {
109
100
// eslint-disable-next-line react/jsx-no-useless-fragment
110
- assertPass ( < React . Fragment /> ) ;
101
+ await assertPass ( < React . Fragment /> ) ;
111
102
} ) ;
112
103
} ) ;
113
104
0 commit comments