@@ -114,6 +114,30 @@ describe('ReactHooks', () => {
114
114
// Because the final values are the same as the current values, the
115
115
// component bails out.
116
116
expect ( root ) . toFlushAndYield ( [ 'Parent: 1, 2' ] ) ;
117
+
118
+ // prepare to check SameValue
119
+ setCounter1 ( 0 / - 1 ) ;
120
+ setCounter2 ( NaN ) ;
121
+ expect ( root ) . toFlushAndYield ( [
122
+ 'Parent: 0, NaN' ,
123
+ 'Child: 0, NaN' ,
124
+ 'Effect: 0, NaN' ,
125
+ ] ) ;
126
+
127
+ // check if re-setting to negative 0 / NaN still bails out
128
+ setCounter1 ( 0 / - 1 ) ;
129
+ setCounter2 ( NaN ) ;
130
+ setCounter2 ( Infinity ) ;
131
+ setCounter2 ( NaN ) ;
132
+ expect ( root ) . toFlushAndYield ( [ 'Parent: 0, NaN' ] ) ;
133
+
134
+ // check if changing negative 0 to positive 0 does not bail out
135
+ setCounter1 ( 0 ) ;
136
+ expect ( root ) . toFlushAndYield ( [
137
+ 'Parent: 0, NaN' ,
138
+ 'Child: 0, NaN' ,
139
+ 'Effect: 0, NaN' ,
140
+ ] ) ;
117
141
} ) ;
118
142
119
143
it ( 'bails out in render phase if all the state is the same and props bail out with memo' , ( ) => {
@@ -375,6 +399,26 @@ describe('ReactHooks', () => {
375
399
setCounter ( 2 ) ;
376
400
expect ( root ) . toFlushAndYield ( [ 'Parent: 2' , 'Child: 2' , 'Effect: 2' ] ) ;
377
401
expect ( root ) . toMatchRenderedOutput ( '2' ) ;
402
+
403
+ // prepare to check SameValue
404
+ setCounter ( 0 ) ;
405
+ expect ( root ) . toFlushAndYield ( [ 'Parent: 0' , 'Child: 0' , 'Effect: 0' ] ) ;
406
+ expect ( root ) . toMatchRenderedOutput ( '0' ) ;
407
+
408
+ // Update to the same state for the first time to flush the queue
409
+ setCounter ( 0 ) ;
410
+ expect ( root ) . toFlushAndYield ( [ 'Parent: 0' ] ) ;
411
+ expect ( root ) . toMatchRenderedOutput ( '0' ) ;
412
+
413
+ // Update again to the same state. Should bail out.
414
+ setCounter ( 0 ) ;
415
+ expect ( root ) . toFlushAndYield ( [ ] ) ;
416
+ expect ( root ) . toMatchRenderedOutput ( '0' ) ;
417
+
418
+ // Update to a different state (positive 0 to negative 0)
419
+ setCounter ( 0 / - 1 ) ;
420
+ expect ( root ) . toFlushAndYield ( [ 'Parent: 0' , 'Child: 0' , 'Effect: 0' ] ) ;
421
+ expect ( root ) . toMatchRenderedOutput ( '0' ) ;
378
422
} ) ;
379
423
380
424
it ( 'bails out multiple times in a row without entering render phase' , ( ) => {
0 commit comments