@@ -68,7 +68,7 @@ describe('useEvent', () => {
68
68
69
69
return (
70
70
< >
71
- < IncrementButton onClick = { onClick } ref = { button } />
71
+ < IncrementButton onClick = { ( ) => onClick ( ) } ref = { button } />
72
72
< Text text = { 'Count: ' + count } />
73
73
</ >
74
74
) ;
@@ -83,17 +83,15 @@ describe('useEvent', () => {
83
83
] ) ;
84
84
85
85
act ( button . current . increment ) ;
86
- expect ( Scheduler ) . toHaveYielded ( [
87
- // Button should not re-render, because its props haven't changed
88
- 'Count: 1' ,
89
- ] ) ;
86
+ expect ( Scheduler ) . toHaveYielded ( [ 'Increment' , 'Count: 1' ] ) ;
90
87
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
91
88
span ( 'Increment' ) ,
92
89
span ( 'Count: 1' ) ,
93
90
] ) ;
94
91
95
92
act ( button . current . increment ) ;
96
93
expect ( Scheduler ) . toHaveYielded ( [
94
+ 'Increment' ,
97
95
// Event should use the updated callback function closed over the new value.
98
96
'Count: 2' ,
99
97
] ) ;
@@ -104,15 +102,15 @@ describe('useEvent', () => {
104
102
105
103
// Increase the increment prop amount
106
104
ReactNoop . render ( < Counter incrementBy = { 10 } /> ) ;
107
- expect ( Scheduler ) . toFlushAndYield ( [ 'Count: 2' ] ) ;
105
+ expect ( Scheduler ) . toFlushAndYield ( [ 'Increment' , ' Count: 2'] ) ;
108
106
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
109
107
span ( 'Increment' ) ,
110
108
span ( 'Count: 2' ) ,
111
109
] ) ;
112
110
113
111
// Event uses the new prop
114
112
act ( button . current . increment ) ;
115
- expect ( Scheduler ) . toHaveYielded ( [ 'Count: 12' ] ) ;
113
+ expect ( Scheduler ) . toHaveYielded ( [ 'Increment' , ' Count: 12'] ) ;
116
114
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
117
115
span ( 'Increment' ) ,
118
116
span ( 'Count: 12' ) ,
@@ -143,7 +141,7 @@ describe('useEvent', () => {
143
141
144
142
return (
145
143
< >
146
- < GreetButton hello = { hello } onClick = { onClick } ref = { button } />
144
+ < GreetButton hello = { hello } onClick = { ( ) => onClick ( ) } ref = { button } />
147
145
< Text text = { 'Greeting: ' + greeting } />
148
146
</ >
149
147
) ;
@@ -158,7 +156,10 @@ describe('useEvent', () => {
158
156
] ) ;
159
157
160
158
act ( button . current . greet ) ;
161
- expect ( Scheduler ) . toHaveYielded ( [ 'Greeting: undefined says hej' ] ) ;
159
+ expect ( Scheduler ) . toHaveYielded ( [
160
+ 'Say hej' ,
161
+ 'Greeting: undefined says hej' ,
162
+ ] ) ;
162
163
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
163
164
span ( 'Say hej' ) ,
164
165
span ( 'Greeting: undefined says hej' ) ,
@@ -186,7 +187,7 @@ describe('useEvent', () => {
186
187
187
188
return (
188
189
< >
189
- < IncrementButton onClick = { onClick } />
190
+ < IncrementButton onClick = { ( ) => onClick ( ) } />
190
191
< Text text = { 'Count: ' + count } />
191
192
</ >
192
193
) ;
@@ -197,6 +198,8 @@ describe('useEvent', () => {
197
198
'An event from useEvent was called during render' ,
198
199
) ;
199
200
201
+ // If something throws, we try one more time synchronously in case the error was
202
+ // caused by a data race. See recoverFromConcurrentError
200
203
expect ( Scheduler ) . toHaveYielded ( [ 'Count: 0' , 'Count: 0' ] ) ;
201
204
} ) ;
202
205
@@ -224,7 +227,7 @@ describe('useEvent', () => {
224
227
225
228
return (
226
229
< >
227
- < IncrementButton onClick = { increment } ref = { button } />
230
+ < IncrementButton onClick = { ( ) => increment ( ) } ref = { button } />
228
231
< Text text = { 'Count: ' + count } />
229
232
</ >
230
233
) ;
@@ -237,6 +240,7 @@ describe('useEvent', () => {
237
240
'Increment' ,
238
241
'Count: 0' ,
239
242
'Effect: by 2' ,
243
+ 'Increment' ,
240
244
'Count: 2' ,
241
245
] ) ;
242
246
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -246,6 +250,7 @@ describe('useEvent', () => {
246
250
247
251
act ( button . current . increment ) ;
248
252
expect ( Scheduler ) . toHaveYielded ( [
253
+ 'Increment' ,
249
254
// Effect should not re-run because the dependency hasn't changed.
250
255
'Count: 3' ,
251
256
] ) ;
@@ -256,6 +261,7 @@ describe('useEvent', () => {
256
261
257
262
act ( button . current . increment ) ;
258
263
expect ( Scheduler ) . toHaveYielded ( [
264
+ 'Increment' ,
259
265
// Event should use the updated callback function closed over the new value.
260
266
'Count: 4' ,
261
267
] ) ;
@@ -267,8 +273,10 @@ describe('useEvent', () => {
267
273
// Increase the increment prop amount
268
274
ReactNoop . render ( < Counter incrementBy = { 10 } /> ) ;
269
275
expect ( Scheduler ) . toFlushAndYield ( [
276
+ 'Increment' ,
270
277
'Count: 4' ,
271
278
'Effect: by 20' ,
279
+ 'Increment' ,
272
280
'Count: 24' ,
273
281
] ) ;
274
282
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -278,7 +286,7 @@ describe('useEvent', () => {
278
286
279
287
// Event uses the new prop
280
288
act ( button . current . increment ) ;
281
- expect ( Scheduler ) . toHaveYielded ( [ 'Count: 34' ] ) ;
289
+ expect ( Scheduler ) . toHaveYielded ( [ 'Increment' , ' Count: 34'] ) ;
282
290
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
283
291
span ( 'Increment' ) ,
284
292
span ( 'Count: 34' ) ,
@@ -309,7 +317,7 @@ describe('useEvent', () => {
309
317
310
318
return (
311
319
< >
312
- < IncrementButton onClick = { increment } ref = { button } />
320
+ < IncrementButton onClick = { ( ) => increment ( ) } ref = { button } />
313
321
< Text text = { 'Count: ' + count } />
314
322
</ >
315
323
) ;
@@ -321,6 +329,7 @@ describe('useEvent', () => {
321
329
'Increment' ,
322
330
'Count: 0' ,
323
331
'Effect: by 2' ,
332
+ 'Increment' ,
324
333
'Count: 2' ,
325
334
] ) ;
326
335
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -330,6 +339,7 @@ describe('useEvent', () => {
330
339
331
340
act ( button . current . increment ) ;
332
341
expect ( Scheduler ) . toHaveYielded ( [
342
+ 'Increment' ,
333
343
// Effect should not re-run because the dependency hasn't changed.
334
344
'Count: 3' ,
335
345
] ) ;
@@ -340,6 +350,7 @@ describe('useEvent', () => {
340
350
341
351
act ( button . current . increment ) ;
342
352
expect ( Scheduler ) . toHaveYielded ( [
353
+ 'Increment' ,
343
354
// Event should use the updated callback function closed over the new value.
344
355
'Count: 4' ,
345
356
] ) ;
@@ -351,8 +362,10 @@ describe('useEvent', () => {
351
362
// Increase the increment prop amount
352
363
ReactNoop . render ( < Counter incrementBy = { 10 } /> ) ;
353
364
expect ( Scheduler ) . toFlushAndYield ( [
365
+ 'Increment' ,
354
366
'Count: 4' ,
355
367
'Effect: by 20' ,
368
+ 'Increment' ,
356
369
'Count: 24' ,
357
370
] ) ;
358
371
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -362,7 +375,7 @@ describe('useEvent', () => {
362
375
363
376
// Event uses the new prop
364
377
act ( button . current . increment ) ;
365
- expect ( Scheduler ) . toHaveYielded ( [ 'Count: 34' ] ) ;
378
+ expect ( Scheduler ) . toHaveYielded ( [ 'Increment' , ' Count: 34'] ) ;
366
379
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
367
380
span ( 'Increment' ) ,
368
381
span ( 'Count: 34' ) ,
@@ -399,7 +412,7 @@ describe('useEvent', () => {
399
412
400
413
return (
401
414
< >
402
- < IncrementButton onClick = { increment } ref = { button } />
415
+ < IncrementButton onClick = { ( ) => increment ( ) } ref = { button } />
403
416
< Text text = { 'Count: ' + count } />
404
417
</ >
405
418
) ;
@@ -411,6 +424,7 @@ describe('useEvent', () => {
411
424
'Increment' ,
412
425
'Count: 0' ,
413
426
'Effect: by 2' ,
427
+ 'Increment' ,
414
428
'Count: 2' ,
415
429
] ) ;
416
430
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -420,6 +434,7 @@ describe('useEvent', () => {
420
434
421
435
act ( button . current . increment ) ;
422
436
expect ( Scheduler ) . toHaveYielded ( [
437
+ 'Increment' ,
423
438
// Effect should not re-run because the dependency hasn't changed.
424
439
'Count: 3' ,
425
440
] ) ;
@@ -430,6 +445,7 @@ describe('useEvent', () => {
430
445
431
446
act ( button . current . increment ) ;
432
447
expect ( Scheduler ) . toHaveYielded ( [
448
+ 'Increment' ,
433
449
// Event should use the updated callback function closed over the new value.
434
450
'Count: 4' ,
435
451
] ) ;
@@ -441,8 +457,10 @@ describe('useEvent', () => {
441
457
// Increase the increment prop amount
442
458
ReactNoop . render ( < Counter incrementBy = { 10 } /> ) ;
443
459
expect ( Scheduler ) . toFlushAndYield ( [
460
+ 'Increment' ,
444
461
'Count: 4' ,
445
462
'Effect: by 20' ,
463
+ 'Increment' ,
446
464
'Count: 24' ,
447
465
] ) ;
448
466
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
@@ -452,7 +470,7 @@ describe('useEvent', () => {
452
470
453
471
// Event uses the new prop
454
472
act ( button . current . increment ) ;
455
- expect ( Scheduler ) . toHaveYielded ( [ 'Count: 34' ] ) ;
473
+ expect ( Scheduler ) . toHaveYielded ( [ 'Increment' , ' Count: 34'] ) ;
456
474
expect ( ReactNoop . getChildren ( ) ) . toEqual ( [
457
475
span ( 'Increment' ) ,
458
476
span ( 'Count: 34' ) ,
@@ -610,7 +628,14 @@ describe('useEvent', () => {
610
628
onVisit ( url ) ;
611
629
} , [ url ] ) ;
612
630
613
- return < AddToCartButton onClick = { onClick } ref = { button } /> ;
631
+ return (
632
+ < AddToCartButton
633
+ onClick = { ( ) => {
634
+ onClick ( ) ;
635
+ } }
636
+ ref = { button }
637
+ />
638
+ ) ;
614
639
}
615
640
616
641
const button = React . createRef ( null ) ;
@@ -626,7 +651,7 @@ describe('useEvent', () => {
626
651
'url: /shop/1, numberOfItems: 0' ,
627
652
] ) ;
628
653
act ( button . current . addToCart ) ;
629
- expect ( Scheduler ) . toFlushWithoutYielding ( ) ;
654
+ expect ( Scheduler ) . toHaveYielded ( [ 'Add to cart' ] ) ;
630
655
631
656
act ( ( ) =>
632
657
ReactNoop . render (
@@ -635,6 +660,9 @@ describe('useEvent', () => {
635
660
</ AppShell > ,
636
661
) ,
637
662
) ;
638
- expect ( Scheduler ) . toHaveYielded ( [ 'url: /shop/2, numberOfItems: 1' ] ) ;
663
+ expect ( Scheduler ) . toHaveYielded ( [
664
+ 'Add to cart' ,
665
+ 'url: /shop/2, numberOfItems: 1' ,
666
+ ] ) ;
639
667
} ) ;
640
668
} ) ;
0 commit comments