11/* eslint-disable react/prefer-stateless-function */
22import * as React from 'react' ;
3- import * as ReactDOM from 'react-dom' ;
43import { expect } from 'chai' ;
54import PropTypes from 'prop-types' ;
5+ import { createRenderer , waitFor } from '@mui/internal-test-utils' ;
66import elementAcceptingRef from './elementAcceptingRef' ;
77
88describe ( 'elementAcceptingRef' , ( ) => {
9+ const { render } = createRenderer ( ) ;
10+
911 function checkPropType ( element : any , required = false ) {
1012 PropTypes . checkPropTypes (
1113 { children : required ? elementAcceptingRef . isRequired : elementAcceptingRef } ,
@@ -20,35 +22,17 @@ describe('elementAcceptingRef', () => {
2022 } ) ;
2123
2224 describe ( 'acceptance when not required' , ( ) => {
23- let rootNode : HTMLElement ;
24-
2525 function assertPass ( element : any , { shouldMount = true } = { } ) {
2626 function testAct ( ) {
2727 checkPropType ( element ) ;
2828 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 ( ) } ) ) ;
3730 }
3831 }
3932
4033 expect ( testAct ) . not . toErrorDev ( ) ;
4134 }
4235
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-
5236 it ( 'accepts nully values' , ( ) => {
5337 assertPass ( undefined , { shouldMount : false } ) ;
5438 assertPass ( null , { shouldMount : false } ) ;
@@ -90,14 +74,25 @@ describe('elementAcceptingRef', () => {
9074 assertPass ( < Component /> ) ;
9175 } ) ;
9276
93- it ( 'accepts lazy' , ( ) => {
77+ it ( 'accepts lazy' , async ( ) => {
9478 const Component = React . lazy ( ( ) =>
9579 Promise . resolve ( {
9680 default : React . forwardRef ( ( props , ref ) => < div { ...props } ref = { ref } /> ) ,
9781 } ) ,
9882 ) ;
9983
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+ } ) ;
10196 } ) ;
10297
10398 it ( 'technically allows other exotics like strict mode' , ( ) => {
0 commit comments