@@ -240,7 +240,7 @@ describe('SimpleEventPlugin', function() {
240
240
} ) ;
241
241
242
242
// @gate experimental
243
- it ( 'flushes pending interactive work before extracting event handler' , ( ) => {
243
+ it ( 'flushes pending interactive work before exiting event handler' , ( ) => {
244
244
container = document . createElement ( 'div' ) ;
245
245
const root = ReactDOM . unstable_createRoot ( container ) ;
246
246
document . body . appendChild ( container ) ;
@@ -292,17 +292,14 @@ describe('SimpleEventPlugin', function() {
292
292
expect ( Scheduler ) . toHaveYielded ( [
293
293
// The handler fired
294
294
'Side-effect' ,
295
- // but the component did not re-render yet, because it's async
295
+ // The component re-rendered synchronously, even in concurrent mode.
296
+ 'render button: disabled' ,
296
297
] ) ;
297
298
298
299
// Click the button again
299
300
click ( ) ;
300
301
expect ( Scheduler ) . toHaveYielded ( [
301
- // Before handling this second click event, the previous interactive
302
- // update is flushed
303
- 'render button: disabled' ,
304
- // The event handler was removed from the button, so there's no second
305
- // side-effect
302
+ // The event handler was removed from the button, so there's no effect.
306
303
] ) ;
307
304
308
305
// The handler should not fire again no matter how many times we
@@ -359,8 +356,8 @@ describe('SimpleEventPlugin', function() {
359
356
360
357
// Click the button a single time
361
358
click ( ) ;
362
- // The counter should not have updated yet because it's async
363
- expect ( button . textContent ) . toEqual ( 'Count: 0 ' ) ;
359
+ // The counter should update synchronously, even in concurrent mode.
360
+ expect ( button . textContent ) . toEqual ( 'Count: 1 ' ) ;
364
361
365
362
// Click the button many more times
366
363
await TestUtils . act ( async ( ) => {
@@ -442,15 +439,10 @@ describe('SimpleEventPlugin', function() {
442
439
button . dispatchEvent ( event ) ;
443
440
}
444
441
445
- // Click the button a single time
446
- click ( ) ;
447
- // Nothing should flush on the first click.
448
- expect ( Scheduler ) . toHaveYielded ( [ ] ) ;
449
- // Click again. This will force the previous discrete update to flush. But
450
- // only the high-pri count will increase.
442
+ // Click the button a single time.
443
+ // This will flush at the end of the event, even in concurrent mode.
451
444
click ( ) ;
452
445
expect ( Scheduler ) . toHaveYielded ( [ 'High-pri count: 1, Low-pri count: 0' ] ) ;
453
- expect ( button . textContent ) . toEqual ( 'High-pri count: 1, Low-pri count: 0' ) ;
454
446
455
447
// Click the button many more times
456
448
click ( ) ;
@@ -460,7 +452,7 @@ describe('SimpleEventPlugin', function() {
460
452
click ( ) ;
461
453
click ( ) ;
462
454
463
- // Flush the remaining work .
455
+ // Each update should synchronously flush, even in concurrent mode .
464
456
expect ( Scheduler ) . toHaveYielded ( [
465
457
'High-pri count: 2, Low-pri count: 0' ,
466
458
'High-pri count: 3, Low-pri count: 0' ,
@@ -470,16 +462,13 @@ describe('SimpleEventPlugin', function() {
470
462
'High-pri count: 7, Low-pri count: 0' ,
471
463
] ) ;
472
464
473
- // Flush the microtask queue
474
- await null ;
475
-
476
- // At the end, both counters should equal the total number of clicks
477
- expect ( Scheduler ) . toHaveYielded ( [ 'High-pri count: 8, Low-pri count: 0' ] ) ;
465
+ // Now flush the scheduler to apply the transition updates.
466
+ // At the end, both counters should equal the total number of clicks.
478
467
expect ( Scheduler ) . toFlushAndYield ( [
479
- 'High-pri count: 8 , Low-pri count: 8 ' ,
468
+ 'High-pri count: 7 , Low-pri count: 7 ' ,
480
469
] ) ;
481
470
482
- expect ( button . textContent ) . toEqual ( 'High-pri count: 8 , Low-pri count: 8 ' ) ;
471
+ expect ( button . textContent ) . toEqual ( 'High-pri count: 7 , Low-pri count: 7 ' ) ;
483
472
} ) ;
484
473
} ) ;
485
474
0 commit comments