File tree Expand file tree Collapse file tree 2 files changed +24
-15
lines changed
packages/react-devtools-shared/src/__tests__ Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -1088,16 +1088,20 @@ describe('Store', () => {
10881088 withErrorsOrWarningsIgnored ( [ 'test-only:' ] , ( ) => {
10891089 act ( ( ) => {
10901090 ReactDOM . render ( < Example /> , container ) ;
1091+ // flush bridge operations
1092+ jest . runOnlyPendingTimers ( ) ;
1093+ } , false ) ;
1094+ } ) ;
10911095
1092- // Flush commit
1093- jest . advanceTimersByTime ( 1 ) ;
1096+ expect ( store ) . toMatchInlineSnapshot ( `
1097+ [root]
1098+ <Example>
1099+ ` ) ;
10941100
1095- expect ( store ) . toMatchInlineSnapshot ( `
1096- [root]
1097- <Example>
1098- ` ) ;
1099- } ) ;
1100- } ) ;
1101+ // flush count after delay
1102+ act ( ( ) => {
1103+ jest . advanceTimersByTime ( 1000 ) ;
1104+ } , false ) ;
11011105
11021106 // After a delay, passive effects should be committed as well
11031107 expect ( store ) . toMatchInlineSnapshot ( `
Original file line number Diff line number Diff line change @@ -14,7 +14,10 @@ import type Store from 'react-devtools-shared/src/devtools/store';
1414import type { ProfilingDataFrontend } from 'react-devtools-shared/src/devtools/views/Profiler/types' ;
1515import type { ElementType } from 'react-devtools-shared/src/types' ;
1616
17- export function act ( callback : Function ) : void {
17+ export function act (
18+ callback : Function ,
19+ recursivelyFlush : boolean = true ,
20+ ) : void {
1821 const { act : actTestRenderer } = require ( 'react-test-renderer' ) ;
1922 const { act : actDOM } = require ( 'react-dom/test-utils' ) ;
2023
@@ -24,13 +27,15 @@ export function act(callback: Function): void {
2427 } ) ;
2528 } ) ;
2629
27- // Flush Bridge operations
28- while ( jest . getTimerCount ( ) > 0 ) {
29- actDOM ( ( ) => {
30- actTestRenderer ( ( ) => {
31- jest . runAllTimers ( ) ;
30+ if ( recursivelyFlush ) {
31+ // Flush Bridge operations
32+ while ( jest . getTimerCount ( ) > 0 ) {
33+ actDOM ( ( ) => {
34+ actTestRenderer ( ( ) => {
35+ jest . runAllTimers ( ) ;
36+ } ) ;
3237 } ) ;
33- } ) ;
38+ }
3439 }
3540}
3641
You can’t perform that action at this time.
0 commit comments