8
8
*/
9
9
10
10
let React ;
11
- let ReactDOM ;
12
11
let ReactDOMClient ;
13
12
let ReactTestUtils ;
14
13
let Scheduler ;
@@ -33,91 +32,57 @@ describe('ReactTestUtils.act()', () => {
33
32
jest . restoreAllMocks ( ) ;
34
33
} ) ;
35
34
36
- // first we run all the tests with concurrent mode
37
- if ( __EXPERIMENTAL__ ) {
38
- let concurrentRoot = null ;
39
- const renderConcurrent = ( el , dom ) => {
40
- concurrentRoot = ReactDOMClient . createRoot ( dom ) ;
41
- if ( __DEV__ ) {
42
- act ( ( ) => concurrentRoot . render ( el ) ) ;
43
- } else {
44
- concurrentRoot . render ( el ) ;
45
- }
46
- } ;
47
-
48
- const unmountConcurrent = _dom => {
49
- if ( __DEV__ ) {
50
- act ( ( ) => {
51
- if ( concurrentRoot !== null ) {
52
- concurrentRoot . unmount ( ) ;
53
- concurrentRoot = null ;
54
- }
55
- } ) ;
56
- } else {
57
- if ( concurrentRoot !== null ) {
58
- concurrentRoot . unmount ( ) ;
59
- concurrentRoot = null ;
35
+ let root = null ;
36
+ const renderConcurrent = ( el , dom ) => {
37
+ root = ReactDOMClient . createRoot ( dom ) ;
38
+ if ( __DEV__ ) {
39
+ act ( ( ) => root . render ( el ) ) ;
40
+ } else {
41
+ root . render ( el ) ;
42
+ }
43
+ } ;
44
+
45
+ const unmountConcurrent = _dom => {
46
+ if ( __DEV__ ) {
47
+ act ( ( ) => {
48
+ if ( root !== null ) {
49
+ root . unmount ( ) ;
50
+ root = null ;
60
51
}
52
+ } ) ;
53
+ } else {
54
+ if ( root !== null ) {
55
+ root . unmount ( ) ;
56
+ root = null ;
61
57
}
62
- } ;
63
-
64
- const rerenderConcurrent = el => {
65
- act ( ( ) => concurrentRoot . render ( el ) ) ;
66
- } ;
67
-
68
- runActTests (
69
- 'concurrent mode' ,
70
- renderConcurrent ,
71
- unmountConcurrent ,
72
- rerenderConcurrent ,
73
- ) ;
74
- }
75
-
76
- // and then in legacy mode
77
-
78
- let legacyDom = null ;
79
- function renderLegacy ( el , dom ) {
80
- legacyDom = dom ;
81
- ReactDOM . render ( el , dom ) ;
82
- }
83
-
84
- function unmountLegacy ( dom ) {
85
- legacyDom = null ;
86
- ReactDOM . unmountComponentAtNode ( dom ) ;
87
- }
58
+ }
59
+ } ;
88
60
89
- function rerenderLegacy ( el ) {
90
- ReactDOM . render ( el , legacyDom ) ;
91
- }
61
+ const rerenderConcurrent = el => {
62
+ act ( ( ) => root . render ( el ) ) ;
63
+ } ;
92
64
93
- runActTests ( 'legacy mode' , renderLegacy , unmountLegacy , rerenderLegacy ) ;
65
+ runActTests ( renderConcurrent , unmountConcurrent , rerenderConcurrent ) ;
94
66
95
67
describe ( 'unacted effects' , ( ) => {
96
68
function App ( ) {
97
69
React . useEffect ( ( ) => { } , [ ] ) ;
98
70
return null ;
99
71
}
100
72
101
- it ( 'does not warn in legacy mode' , ( ) => {
102
- expect ( ( ) => {
103
- ReactDOM . render ( < App /> , document . createElement ( 'div' ) ) ;
104
- } ) . toErrorDev ( [ ] ) ;
105
- } ) ;
106
-
107
73
// @gate __DEV__
108
- it ( 'does not warn in concurrent mode ' , ( ) => {
109
- const root = ReactDOMClient . createRoot ( document . createElement ( 'div' ) ) ;
74
+ it ( 'does not warn' , ( ) => {
75
+ root = ReactDOMClient . createRoot ( document . createElement ( 'div' ) ) ;
110
76
act ( ( ) => root . render ( < App /> ) ) ;
111
77
} ) ;
112
78
} ) ;
113
79
} ) ;
114
80
115
- function runActTests ( label , render , unmount , rerender ) {
116
- describe ( label , ( ) => {
81
+ function runActTests ( render , unmount , rerender ) {
82
+ describe ( 'concurrent render' , ( ) => {
117
83
beforeEach ( ( ) => {
118
84
jest . resetModules ( ) ;
119
85
React = require ( 'react' ) ;
120
- ReactDOM = require ( 'react-dom' ) ;
121
86
ReactDOMClient = require ( 'react-dom/client' ) ;
122
87
ReactTestUtils = require ( 'react-dom/test-utils' ) ;
123
88
Scheduler = require ( 'scheduler' ) ;
@@ -703,14 +668,6 @@ function runActTests(label, render, unmount, rerender) {
703
668
704
669
// @gate __DEV__
705
670
it ( 'triggers fallbacks if available' , async ( ) => {
706
- if ( label !== 'legacy mode' ) {
707
- // FIXME: Support for Concurrent Root intentionally removed
708
- // from the public version of `act`. It will be added back in
709
- // a future major version, before the Concurrent Root is released.
710
- // Consider skipping all non-Legacy tests in this suite until then.
711
- return ;
712
- }
713
-
714
671
let resolved = false ;
715
672
let resolve ;
716
673
const promise = new Promise ( _resolve => {
@@ -759,16 +716,8 @@ function runActTests(label, render, unmount, rerender) {
759
716
} ) ;
760
717
} ) ;
761
718
762
- if ( label === 'concurrent mode' ) {
763
- // In Concurrent Mode, refresh transitions delay indefinitely.
764
- expect ( document . querySelector ( '[data-test-id=spinner]' ) ) . toBeNull ( ) ;
765
- } else {
766
- // In Legacy Mode, all fallbacks are forced to display,
767
- // even during a refresh transition.
768
- expect (
769
- document . querySelector ( '[data-test-id=spinner]' ) ,
770
- ) . not . toBeNull ( ) ;
771
- }
719
+ // In Concurrent Mode, refresh transitions delay indefinitely.
720
+ expect ( document . querySelector ( '[data-test-id=spinner]' ) ) . toBeNull ( ) ;
772
721
773
722
// resolve the promise
774
723
await act ( async ( ) => {
0 commit comments