1111
1212// Requires
1313let React ;
14- let ReactDOM ;
15- let ReactTestUtils ;
14+ let ReactDOMClient ;
15+ let act ;
1616
1717// Test components
1818let LowerLevelComposite ;
1919let MyCompositeComponent ;
2020
21- let expectSingleChildlessDiv ;
22-
2321/**
2422 * Integration test, testing the combination of JSX with our unit of
2523 * abstraction, `ReactCompositeComponent` does not ever add superfluous DOM
@@ -28,8 +26,8 @@ let expectSingleChildlessDiv;
2826describe ( 'ReactCompositeComponentDOMMinimalism' , ( ) => {
2927 beforeEach ( ( ) => {
3028 React = require ( 'react' ) ;
31- ReactDOM = require ( 'react-dom' ) ;
32- ReactTestUtils = require ( 'react-dom/ test-utils' ) ;
29+ ReactDOMClient = require ( 'react-dom/client ' ) ;
30+ act = require ( 'internal- test-utils' ) . act ;
3331
3432 LowerLevelComposite = class extends React . Component {
3533 render ( ) {
@@ -42,39 +40,51 @@ describe('ReactCompositeComponentDOMMinimalism', () => {
4240 return < LowerLevelComposite > { this . props . children } </ LowerLevelComposite > ;
4341 }
4442 } ;
45-
46- expectSingleChildlessDiv = function ( instance ) {
47- const el = ReactDOM . findDOMNode ( instance ) ;
48- expect ( el . tagName ) . toBe ( 'DIV' ) ;
49- expect ( el . children . length ) . toBe ( 0 ) ;
50- } ;
5143 } ) ;
5244
53- it ( 'should not render extra nodes for non-interpolated text' , ( ) => {
54- let instance = < MyCompositeComponent > A string child</ MyCompositeComponent > ;
55- instance = ReactTestUtils . renderIntoDocument ( instance ) ;
56- expectSingleChildlessDiv ( instance ) ;
45+ it ( 'should not render extra nodes for non-interpolated text' , async ( ) => {
46+ const container = document . createElement ( 'div' ) ;
47+ const root = ReactDOMClient . createRoot ( container ) ;
48+ await act ( ( ) => {
49+ root . render ( < MyCompositeComponent > A string child</ MyCompositeComponent > ) ;
50+ } ) ;
51+
52+ const instance = container . firstChild ;
53+ expect ( instance . tagName ) . toBe ( 'DIV' ) ;
54+ expect ( instance . children . length ) . toBe ( 0 ) ;
5755 } ) ;
5856
59- it ( 'should not render extra nodes for non-interpolated text' , ( ) => {
60- let instance = (
61- < MyCompositeComponent > { 'Interpolated String Child' } </ MyCompositeComponent >
62- ) ;
63- instance = ReactTestUtils . renderIntoDocument ( instance ) ;
64- expectSingleChildlessDiv ( instance ) ;
57+ it ( 'should not render extra nodes for non-interpolated text' , async ( ) => {
58+ const container = document . createElement ( 'div' ) ;
59+ const root = ReactDOMClient . createRoot ( container ) ;
60+ await act ( ( ) => {
61+ root . render (
62+ < MyCompositeComponent >
63+ { 'Interpolated String Child' }
64+ </ MyCompositeComponent > ,
65+ ) ;
66+ } ) ;
67+
68+ const instance = container . firstChild ;
69+ expect ( instance . tagName ) . toBe ( 'DIV' ) ;
70+ expect ( instance . children . length ) . toBe ( 0 ) ;
6571 } ) ;
6672
67- it ( 'should not render extra nodes for non-interpolated text' , ( ) => {
68- let instance = (
69- < MyCompositeComponent >
70- < ul > This text causes no children in ul, just innerHTML</ ul >
71- </ MyCompositeComponent >
72- ) ;
73- instance = ReactTestUtils . renderIntoDocument ( instance ) ;
74- const el = ReactDOM . findDOMNode ( instance ) ;
75- expect ( el . tagName ) . toBe ( 'DIV' ) ;
76- expect ( el . children . length ) . toBe ( 1 ) ;
77- expect ( el . children [ 0 ] . tagName ) . toBe ( 'UL' ) ;
78- expect ( el . children [ 0 ] . children . length ) . toBe ( 0 ) ;
73+ it ( 'should not render extra nodes for non-interpolated text' , async ( ) => {
74+ const container = document . createElement ( 'div' ) ;
75+ const root = ReactDOMClient . createRoot ( container ) ;
76+ await act ( ( ) => {
77+ root . render (
78+ < MyCompositeComponent >
79+ < ul > This text causes no children in ul, just innerHTML</ ul >
80+ </ MyCompositeComponent > ,
81+ ) ;
82+ } ) ;
83+
84+ const instance = container . firstChild ;
85+ expect ( instance . tagName ) . toBe ( 'DIV' ) ;
86+ expect ( instance . children . length ) . toBe ( 1 ) ;
87+ expect ( instance . children [ 0 ] . tagName ) . toBe ( 'UL' ) ;
88+ expect ( instance . children [ 0 ] . children . length ) . toBe ( 0 ) ;
7989 } ) ;
8090} ) ;
0 commit comments