@@ -135,6 +135,7 @@ function runActTests(label, render, unmount, rerender) {
135
135
} ) ;
136
136
137
137
describe ( 'sync' , ( ) => {
138
+ // @gate __DEV__
138
139
it ( 'can use act to flush effects' , ( ) => {
139
140
function App ( ) {
140
141
React . useEffect ( ( ) => {
@@ -150,6 +151,7 @@ function runActTests(label, render, unmount, rerender) {
150
151
expect ( Scheduler ) . toHaveYielded ( [ 100 ] ) ;
151
152
} ) ;
152
153
154
+ // @gate __DEV__
153
155
it ( 'flushes effects on every call' , async ( ) => {
154
156
function App ( ) {
155
157
const [ ctr , setCtr ] = React . useState ( 0 ) ;
@@ -186,6 +188,7 @@ function runActTests(label, render, unmount, rerender) {
186
188
expect ( button . innerHTML ) . toBe ( '5' ) ;
187
189
} ) ;
188
190
191
+ // @gate __DEV__
189
192
it ( "should keep flushing effects until they're done" , ( ) => {
190
193
function App ( ) {
191
194
const [ ctr , setCtr ] = React . useState ( 0 ) ;
@@ -204,6 +207,7 @@ function runActTests(label, render, unmount, rerender) {
204
207
expect ( container . innerHTML ) . toBe ( '5' ) ;
205
208
} ) ;
206
209
210
+ // @gate __DEV__
207
211
it ( 'should flush effects only on exiting the outermost act' , ( ) => {
208
212
function App ( ) {
209
213
React . useEffect ( ( ) => {
@@ -224,6 +228,7 @@ function runActTests(label, render, unmount, rerender) {
224
228
expect ( Scheduler ) . toHaveYielded ( [ 0 ] ) ;
225
229
} ) ;
226
230
231
+ // @gate __DEV__
227
232
it ( 'warns if a setState is called outside of act(...)' , ( ) => {
228
233
let setValue = null ;
229
234
function App ( ) {
@@ -250,6 +255,7 @@ function runActTests(label, render, unmount, rerender) {
250
255
jest . useRealTimers ( ) ;
251
256
} ) ;
252
257
258
+ // @gate __DEV__
253
259
it ( 'lets a ticker update' , ( ) => {
254
260
function App ( ) {
255
261
const [ toggle , setToggle ] = React . useState ( 0 ) ;
@@ -272,6 +278,7 @@ function runActTests(label, render, unmount, rerender) {
272
278
expect ( container . innerHTML ) . toBe ( '1' ) ;
273
279
} ) ;
274
280
281
+ // @gate __DEV__
275
282
it ( 'can use the async version to catch microtasks' , async ( ) => {
276
283
function App ( ) {
277
284
const [ toggle , setToggle ] = React . useState ( 0 ) ;
@@ -294,6 +301,7 @@ function runActTests(label, render, unmount, rerender) {
294
301
expect ( container . innerHTML ) . toBe ( '1' ) ;
295
302
} ) ;
296
303
304
+ // @gate __DEV__
297
305
it ( 'can handle cascading promises with fake timers' , async ( ) => {
298
306
// this component triggers an effect, that waits a tick,
299
307
// then sets state. repeats this 5 times.
@@ -317,6 +325,7 @@ function runActTests(label, render, unmount, rerender) {
317
325
expect ( container . innerHTML ) . toBe ( '5' ) ;
318
326
} ) ;
319
327
328
+ // @gate __DEV__
320
329
it ( 'flushes immediate re-renders with act' , ( ) => {
321
330
function App ( ) {
322
331
const [ ctr , setCtr ] = React . useState ( 0 ) ;
@@ -346,6 +355,7 @@ function runActTests(label, render, unmount, rerender) {
346
355
} ) ;
347
356
} ) ;
348
357
358
+ // @gate __DEV__
349
359
it ( 'warns if you return a value inside act' , ( ) => {
350
360
expect ( ( ) => act ( ( ) => null ) ) . toErrorDev (
351
361
[
@@ -361,6 +371,7 @@ function runActTests(label, render, unmount, rerender) {
361
371
) ;
362
372
} ) ;
363
373
374
+ // @gate __DEV__
364
375
it ( 'warns if you try to await a sync .act call' , ( ) => {
365
376
expect ( ( ) => act ( ( ) => { } ) . then ( ( ) => { } ) ) . toErrorDev (
366
377
[
@@ -372,6 +383,7 @@ function runActTests(label, render, unmount, rerender) {
372
383
} ) ;
373
384
374
385
describe ( 'asynchronous tests' , ( ) => {
386
+ // @gate __DEV__
375
387
it ( 'works with timeouts' , async ( ) => {
376
388
function App ( ) {
377
389
const [ ctr , setCtr ] = React . useState ( 0 ) ;
@@ -396,6 +408,7 @@ function runActTests(label, render, unmount, rerender) {
396
408
expect ( container . innerHTML ) . toBe ( '1' ) ;
397
409
} ) ;
398
410
411
+ // @gate __DEV__
399
412
it ( 'flushes microtasks before exiting' , async ( ) => {
400
413
function App ( ) {
401
414
const [ ctr , setCtr ] = React . useState ( 0 ) ;
@@ -418,6 +431,7 @@ function runActTests(label, render, unmount, rerender) {
418
431
expect ( container . innerHTML ) . toEqual ( '1' ) ;
419
432
} ) ;
420
433
434
+ // @gate __DEV__
421
435
it ( 'warns if you do not await an act call' , async ( ) => {
422
436
spyOnDevAndProd ( console , 'error' ) ;
423
437
act ( async ( ) => { } ) ;
@@ -431,6 +445,7 @@ function runActTests(label, render, unmount, rerender) {
431
445
}
432
446
} ) ;
433
447
448
+ // @gate __DEV__
434
449
it ( 'warns if you try to interleave multiple act calls' , async ( ) => {
435
450
spyOnDevAndProd ( console , 'error' ) ;
436
451
// let's try to cheat and spin off a 'thread' with an act call
@@ -450,6 +465,7 @@ function runActTests(label, render, unmount, rerender) {
450
465
}
451
466
} ) ;
452
467
468
+ // @gate __DEV__
453
469
it ( 'async commits and effects are guaranteed to be flushed' , async ( ) => {
454
470
function App ( ) {
455
471
const [ state , setState ] = React . useState ( 0 ) ;
@@ -475,6 +491,7 @@ function runActTests(label, render, unmount, rerender) {
475
491
expect ( container . innerHTML ) . toBe ( '1' ) ;
476
492
} ) ;
477
493
494
+ // @gate __DEV__
478
495
it ( 'can handle cascading promises' , async ( ) => {
479
496
// this component triggers an effect, that waits a tick,
480
497
// then sets state. repeats this 5 times.
@@ -501,6 +518,7 @@ function runActTests(label, render, unmount, rerender) {
501
518
} ) ;
502
519
503
520
describe ( 'error propagation' , ( ) => {
521
+ // @gate __DEV__
504
522
it ( 'propagates errors - sync' , ( ) => {
505
523
let err ;
506
524
try {
@@ -515,6 +533,7 @@ function runActTests(label, render, unmount, rerender) {
515
533
}
516
534
} ) ;
517
535
536
+ // @gate __DEV__
518
537
it ( 'should propagate errors from effects - sync' , ( ) => {
519
538
function App ( ) {
520
539
React . useEffect ( ( ) => {
@@ -536,6 +555,7 @@ function runActTests(label, render, unmount, rerender) {
536
555
}
537
556
} ) ;
538
557
558
+ // @gate __DEV__
539
559
it ( 'propagates errors - async' , async ( ) => {
540
560
let err ;
541
561
try {
@@ -551,6 +571,7 @@ function runActTests(label, render, unmount, rerender) {
551
571
}
552
572
} ) ;
553
573
574
+ // @gate __DEV__
554
575
it ( 'should cleanup after errors - sync' , ( ) => {
555
576
function App ( ) {
556
577
React . useEffect ( ( ) => {
@@ -576,6 +597,7 @@ function runActTests(label, render, unmount, rerender) {
576
597
}
577
598
} ) ;
578
599
600
+ // @gate __DEV__
579
601
it ( 'should cleanup after errors - async' , async ( ) => {
580
602
function App ( ) {
581
603
async function somethingAsync ( ) {
@@ -611,6 +633,7 @@ function runActTests(label, render, unmount, rerender) {
611
633
if ( __DEV__ && __EXPERIMENTAL__ ) {
612
634
// todo - remove __DEV__ check once we start using testing builds
613
635
636
+ // @gate __DEV__
614
637
it ( 'triggers fallbacks if available' , async ( ) => {
615
638
if ( label !== 'legacy mode' ) {
616
639
// FIXME: Support for Concurrent Root intentionally removed
@@ -691,25 +714,12 @@ function runActTests(label, render, unmount, rerender) {
691
714
} ) ;
692
715
}
693
716
} ) ;
694
- describe ( 'warn in prod mode' , ( ) => {
717
+ describe ( 'throw in prod mode' , ( ) => {
718
+ // @gate !__DEV__
695
719
it ( 'warns if you try to use act() in prod mode' , ( ) => {
696
- const spy = spyOnDevAndProd ( console , 'error' ) ;
697
-
698
- act ( ( ) => { } ) ;
699
-
700
- if ( ! __DEV__ ) {
701
- expect ( console . error ) . toHaveBeenCalledTimes ( 1 ) ;
702
- expect ( console . error . calls . argsFor ( 0 ) [ 0 ] ) . toContain (
703
- 'act(...) is not supported in production builds of React' ,
704
- ) ;
705
- } else {
706
- expect ( console . error ) . toHaveBeenCalledTimes ( 0 ) ;
707
- }
708
-
709
- spy . calls . reset ( ) ;
710
- // does not warn twice
711
- act ( ( ) => { } ) ;
712
- expect ( console . error ) . toHaveBeenCalledTimes ( 0 ) ;
720
+ expect ( ( ) => act ( ( ) => { } ) ) . toThrow (
721
+ 'act(...) is not supported in production builds of React' ,
722
+ ) ;
713
723
} ) ;
714
724
} ) ;
715
725
} ) ;
0 commit comments