@@ -31,6 +31,7 @@ describe('ReactTestUtils', () => {
31
31
expect ( Object . keys ( ReactTestUtils . Simulate ) . sort ( ) ) . toMatchSnapshot ( ) ;
32
32
} ) ;
33
33
34
+ // @gate !disableDOMTestUtils
34
35
it ( 'gives Jest mocks a passthrough implementation with mockComponent()' , async ( ) => {
35
36
class MockedComponent extends React . Component {
36
37
render ( ) {
@@ -60,6 +61,7 @@ describe('ReactTestUtils', () => {
60
61
expect ( container . textContent ) . toBe ( 'Hello' ) ;
61
62
} ) ;
62
63
64
+ // @gate !disableDOMTestUtils
63
65
it ( 'can scryRenderedComponentsWithType' , async ( ) => {
64
66
class Child extends React . Component {
65
67
render ( ) {
@@ -88,6 +90,7 @@ describe('ReactTestUtils', () => {
88
90
expect ( scryResults . length ) . toBe ( 1 ) ;
89
91
} ) ;
90
92
93
+ // @gate !disableDOMTestUtils
91
94
it ( 'can scryRenderedDOMComponentsWithClass with TextComponent' , async ( ) => {
92
95
class Wrapper extends React . Component {
93
96
render ( ) {
@@ -112,6 +115,7 @@ describe('ReactTestUtils', () => {
112
115
expect ( scryResults . length ) . toBe ( 0 ) ;
113
116
} ) ;
114
117
118
+ // @gate !disableDOMTestUtils
115
119
it ( 'can scryRenderedDOMComponentsWithClass with className contains \\n' , async ( ) => {
116
120
class Wrapper extends React . Component {
117
121
render ( ) {
@@ -136,6 +140,7 @@ describe('ReactTestUtils', () => {
136
140
expect ( scryResults . length ) . toBe ( 1 ) ;
137
141
} ) ;
138
142
143
+ // @gate !disableDOMTestUtils
139
144
it ( 'can scryRenderedDOMComponentsWithClass with multiple classes' , async ( ) => {
140
145
class Wrapper extends React . Component {
141
146
render ( ) {
@@ -187,6 +192,7 @@ describe('ReactTestUtils', () => {
187
192
expect ( scryResults5 . length ) . toBe ( 0 ) ;
188
193
} ) ;
189
194
195
+ // @gate !disableDOMTestUtils
190
196
it ( 'traverses children in the correct order' , async ( ) => {
191
197
class Wrapper extends React . Component {
192
198
render ( ) {
@@ -225,6 +231,7 @@ describe('ReactTestUtils', () => {
225
231
expect ( log ) . toEqual ( [ 'orangepurple' , 'orange' , 'purple' ] ) ;
226
232
} ) ;
227
233
234
+ // @gate !disableDOMTestUtils
228
235
it ( 'should support injected wrapper components as DOM components' , async ( ) => {
229
236
const injectedDOMComponents = [
230
237
'button' ,
@@ -291,6 +298,7 @@ describe('ReactTestUtils', () => {
291
298
expect ( ReactTestUtils . isDOMComponent ( component . bodyRef . current ) ) . toBe ( true ) ;
292
299
} ) ;
293
300
301
+ // @gate !disableDOMTestUtils
294
302
it ( 'can scry with stateless components involved' , async ( ) => {
295
303
const Function = ( ) => (
296
304
< div >
@@ -320,6 +328,7 @@ describe('ReactTestUtils', () => {
320
328
expect ( hrs . length ) . toBe ( 2 ) ;
321
329
} ) ;
322
330
331
+ // @gate !disableDOMTestUtils
323
332
it ( 'provides a clear error when passing invalid objects to scry' , ( ) => {
324
333
// This is probably too relaxed but it's existing behavior.
325
334
ReactTestUtils . findAllInRenderedTree ( null , 'span' ) ;
@@ -377,6 +386,7 @@ describe('ReactTestUtils', () => {
377
386
} ) ;
378
387
379
388
describe ( 'Simulate' , ( ) => {
389
+ // @gate !disableDOMTestUtils
380
390
it ( 'should change the value of an input field' , async ( ) => {
381
391
const obj = {
382
392
handler : function ( e ) {
@@ -399,6 +409,7 @@ describe('ReactTestUtils', () => {
399
409
) ;
400
410
} ) ;
401
411
412
+ // @gate !disableDOMTestUtils
402
413
it ( 'should change the value of an input field in a component' , async ( ) => {
403
414
class SomeComponent extends React . Component {
404
415
inputRef = React . createRef ( ) ;
@@ -442,6 +453,7 @@ describe('ReactTestUtils', () => {
442
453
) ;
443
454
} ) ;
444
455
456
+ // @gate !disableDOMTestUtils
445
457
it ( 'should not warn when used with extra properties' , async ( ) => {
446
458
const CLIENT_X = 100 ;
447
459
@@ -468,6 +480,7 @@ describe('ReactTestUtils', () => {
468
480
} ) ;
469
481
} ) ;
470
482
483
+ // @gate !disableDOMTestUtils
471
484
it ( 'should set the type of the event' , async ( ) => {
472
485
let event ;
473
486
const stub = jest . fn ( ) . mockImplementation ( e => {
@@ -488,6 +501,7 @@ describe('ReactTestUtils', () => {
488
501
expect ( event . nativeEvent . type ) . toBe ( 'keydown' ) ;
489
502
} ) ;
490
503
504
+ // @gate !disableDOMTestUtils
491
505
it ( 'should work with renderIntoDocument' , async ( ) => {
492
506
const onChange = jest . fn ( ) ;
493
507
@@ -520,6 +534,7 @@ describe('ReactTestUtils', () => {
520
534
) ;
521
535
} ) ;
522
536
537
+ // @gate !disableDOMTestUtils
523
538
it ( 'should have mouse enter simulated by test utils' , async ( ) => {
524
539
const idCallOrder = [ ] ;
525
540
const recordID = function ( id ) {
@@ -560,8 +575,17 @@ describe('ReactTestUtils', () => {
560
575
} ) ;
561
576
expect ( idCallOrder ) . toEqual ( [ CHILD ] ) ;
562
577
} ) ;
578
+
579
+ // @gate disableDOMTestUtils
580
+ it ( 'throws' , async ( ) => {
581
+ expect ( ReactTestUtils . Simulate . click ) . toThrow (
582
+ '`Simulate` was removed from `react-dom/test-utils`. ' +
583
+ 'See https://react.dev/warnings/react-dom-test-utils for more info.' ,
584
+ ) ;
585
+ } ) ;
563
586
} ) ;
564
587
588
+ // @gate !disableDOMTestUtils
565
589
it ( 'should call setState callback with no arguments' , async ( ) => {
566
590
let mockArgs ;
567
591
class Component extends React . Component {
@@ -573,14 +597,12 @@ describe('ReactTestUtils', () => {
573
597
}
574
598
}
575
599
576
- const container = document . createElement ( 'div' ) ;
577
- const root = ReactDOMClient . createRoot ( container ) ;
578
- await act ( ( ) => {
579
- root . render ( < Component /> ) ;
580
- } ) ;
600
+ ReactTestUtils . renderIntoDocument ( < Component /> ) ;
581
601
582
602
expect ( mockArgs . length ) . toEqual ( 0 ) ;
583
603
} ) ;
604
+
605
+ // @gate !disableDOMTestUtils
584
606
it ( 'should find rendered component with type in document' , async ( ) => {
585
607
class MyComponent extends React . Component {
586
608
render ( ) {
@@ -602,4 +624,12 @@ describe('ReactTestUtils', () => {
602
624
603
625
expect ( renderedComponentType ) . toBe ( instance ) ;
604
626
} ) ;
627
+
628
+ // @gate disableDOMTestUtils
629
+ it ( 'throws on every removed function' , async ( ) => {
630
+ expect ( ReactTestUtils . isDOMComponent ) . toThrow (
631
+ '`isDOMComponent` was removed from `react-dom/test-utils`. ' +
632
+ 'See https://react.dev/warnings/react-dom-test-utils for more info.' ,
633
+ ) ;
634
+ } ) ;
605
635
} ) ;
0 commit comments