22
33import * as d3 from 'd3' ;
44import * as React from 'react' ;
5- import ReactDOM from 'react-dom' ;
5+ import { createRoot } from 'react-dom/client ' ;
66import { shallow } from 'enzyme' ;
77import Background from '../../src/components/background' ;
88import Defs from '../../src/components/defs' ;
99import GraphUtils from '../../src/utilities/graph-util' ;
1010import GraphView from '../../src/components/graph-view' ;
1111
12- jest . mock ( 'react-dom' , ( ) => {
13- return { } ;
14- } ) ;
12+ jest . mock ( 'react-dom/client' , ( ) => ( {
13+ ...jest . requireActual ( 'react-dom/client' ) ,
14+ createRoot : jest . fn ( ) ,
15+ } ) ) ;
1516
1617describe ( 'GraphView component' , ( ) => {
1718 let output = null ;
@@ -32,6 +33,7 @@ describe('GraphView component', () => {
3233 let onUndo ;
3334 let instance ;
3435 let nodeKey ;
36+ let render ;
3537
3638 beforeEach ( ( ) => {
3739 nodes = [ ] ;
@@ -50,7 +52,9 @@ describe('GraphView component', () => {
5052 onSwapEdge = jest . fn ( ) ;
5153 onSelectEdge = jest . fn ( ) ;
5254 onUndo = jest . fn ( ) ;
53- ReactDOM . render = jest . fn ( ) ;
55+ render = jest . fn ( ) ;
56+ // $FlowFixMe[prop-missing]
57+ createRoot . mockImplementation ( ( ) => ( { render : render } ) ) ;
5458
5559 jest . spyOn ( document , 'querySelector' ) . mockReturnValue ( {
5660 getBoundingClientRect : jest . fn ( ) . mockReturnValue ( {
@@ -142,14 +146,14 @@ describe('GraphView component', () => {
142146 showGraphControls : false ,
143147 } ) ;
144148 instance . renderGraphControls ( ) ;
145- expect ( ReactDOM . render ) . not . toHaveBeenCalled ( ) ;
149+ expect ( render ) . not . toHaveBeenCalled ( ) ;
146150
147151 output . setProps ( {
148152 showGraphControls : true ,
149153 } ) ;
150154 } ) ;
151155
152- it ( 'uses ReactDOM.render to async render the GraphControls' , ( ) => {
156+ it ( 'uses createRoot to async render the GraphControls' , ( ) => {
153157 output . setProps ( {
154158 showGraphControls : true ,
155159 } ) ;
@@ -159,7 +163,7 @@ describe('GraphView component', () => {
159163 } ,
160164 } ) ;
161165 instance . renderGraphControls ( ) ;
162- expect ( ReactDOM . render ) . toHaveBeenCalled ( ) ;
166+ expect ( render ) . toHaveBeenCalled ( ) ;
163167 } ) ;
164168 } ) ;
165169
@@ -330,7 +334,9 @@ describe('GraphView component', () => {
330334 instance . entities = {
331335 appendChild : jest . fn ( ) ,
332336 } ;
333- ReactDOM . render = jest . fn ( ) ;
337+ render = jest . fn ( ) ;
338+ // $FlowFixMe[prop-missing]
339+ createRoot . mockImplementation ( ( ) => ( { render : render } ) ) ;
334340 } ) ;
335341
336342 it ( 'appends an edge element into the entities element' , ( ) => {
@@ -380,7 +386,7 @@ describe('GraphView component', () => {
380386 instance . renderEdge ( 'test' , element , edge ) ;
381387
382388 expect ( instance . entities . appendChild ) . not . toHaveBeenCalled ( ) ;
383- expect ( ReactDOM . render ) . toHaveBeenCalledWith ( element , container ) ;
389+ expect ( render ) . toHaveBeenCalledWith ( element ) ;
384390 } ) ;
385391 } ) ;
386392
@@ -591,7 +597,9 @@ describe('GraphView component', () => {
591597 instance . entities = {
592598 appendChild : jest . fn ( ) ,
593599 } ;
594- ReactDOM . render = jest . fn ( ) ;
600+ render = jest . fn ( ) ;
601+ // $FlowFixMe[prop-missing]
602+ createRoot . mockImplementation ( ( ) => ( { render : render } ) ) ;
595603 } ) ;
596604
597605 it ( 'appends a node element into the entities element' , ( ) => {
@@ -629,7 +637,7 @@ describe('GraphView component', () => {
629637 instance . renderNode ( 'test' , element ) ;
630638
631639 expect ( instance . entities . appendChild ) . not . toHaveBeenCalled ( ) ;
632- expect ( ReactDOM . render ) . toHaveBeenCalledWith ( element , container ) ;
640+ expect ( render ) . toHaveBeenCalledWith ( element ) ;
633641 } ) ;
634642 } ) ;
635643
0 commit comments