@@ -65,16 +65,16 @@ describe('createSubscription', () => {
65
65
) ;
66
66
67
67
// Updates while subscribed should re-render the child component
68
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'default' ] ) ;
68
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'default' ] ) ;
69
69
observable . next ( 123 ) ;
70
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 123 ] ) ;
70
+ expect ( ReactNoop ) . toFlushAndYield ( [ 123 ] ) ;
71
71
observable . next ( 'abc' ) ;
72
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'abc' ] ) ;
72
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'abc' ] ) ;
73
73
74
74
// Unmounting the subscriber should remove listeners
75
75
ReactNoop . render ( < div /> ) ;
76
76
observable . next ( 456 ) ;
77
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ ] ) ;
77
+ expect ( ReactNoop ) . toFlushAndYield ( [ ] ) ;
78
78
} ) ;
79
79
80
80
it ( 'should support observable types like RxJS ReplaySubject' , ( ) => {
@@ -102,13 +102,13 @@ describe('createSubscription', () => {
102
102
const observable = createReplaySubject ( 'initial' ) ;
103
103
104
104
ReactNoop . render ( < Subscription source = { observable } > { render } </ Subscription > ) ;
105
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'initial' ] ) ;
105
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'initial' ] ) ;
106
106
observable . next ( 'updated' ) ;
107
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'updated' ] ) ;
107
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'updated' ] ) ;
108
108
109
109
// Unsetting the subscriber prop should reset subscribed values
110
110
ReactNoop . render ( < Subscription > { render } </ Subscription > ) ;
111
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'default' ] ) ;
111
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'default' ] ) ;
112
112
} ) ;
113
113
114
114
describe ( 'Promises' , ( ) => {
@@ -141,19 +141,19 @@ describe('createSubscription', () => {
141
141
142
142
// Test a promise that resolves after render
143
143
ReactNoop . render ( < Subscription source = { promiseA } > { render } </ Subscription > ) ;
144
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'loading' ] ) ;
144
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'loading' ] ) ;
145
145
resolveA ( true ) ;
146
146
await promiseA ;
147
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'finished' ] ) ;
147
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'finished' ] ) ;
148
148
149
149
// Test a promise that resolves before render
150
150
// Note that this will require an extra render anyway,
151
151
// Because there is no way to synchronously get a Promise's value
152
152
rejectB ( false ) ;
153
153
ReactNoop . render ( < Subscription source = { promiseB } > { render } </ Subscription > ) ;
154
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'loading' ] ) ;
154
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'loading' ] ) ;
155
155
await promiseB . catch ( ( ) => true ) ;
156
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'failed' ] ) ;
156
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'failed' ] ) ;
157
157
} ) ;
158
158
159
159
it ( 'should still work if unsubscription is managed incorrectly' , async ( ) => {
@@ -177,17 +177,17 @@ describe('createSubscription', () => {
177
177
178
178
// Subscribe first to Promise A then Promise B
179
179
ReactNoop . render ( < Subscription source = { promiseA } > { render } </ Subscription > ) ;
180
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'default' ] ) ;
180
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'default' ] ) ;
181
181
ReactNoop . render ( < Subscription source = { promiseB } > { render } </ Subscription > ) ;
182
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'default' ] ) ;
182
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'default' ] ) ;
183
183
184
184
// Resolve both Promises
185
185
resolveB ( 123 ) ;
186
186
resolveA ( 'abc' ) ;
187
187
await Promise . all ( [ promiseA , promiseB ] ) ;
188
188
189
189
// Ensure that only Promise B causes an update
190
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 123 ] ) ;
190
+ expect ( ReactNoop ) . toFlushAndYield ( [ 123 ] ) ;
191
191
} ) ;
192
192
193
193
it ( 'should not call setState for a Promise that resolves after unmount' , async ( ) => {
@@ -211,11 +211,11 @@ describe('createSubscription', () => {
211
211
} ) ;
212
212
213
213
ReactNoop . render ( < Subscription source = { promise } > { render } </ Subscription > ) ;
214
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'rendered' ] ) ;
214
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'rendered' ] ) ;
215
215
216
216
// Unmount
217
217
ReactNoop . render ( null ) ;
218
- ReactNoop . flush ( ) ;
218
+ expect ( ReactNoop ) . toFlushWithoutYielding ( ) ;
219
219
220
220
// Resolve Promise should not trigger a setState warning
221
221
resolvePromise ( true ) ;
@@ -245,21 +245,21 @@ describe('createSubscription', () => {
245
245
) ;
246
246
247
247
// Updates while subscribed should re-render the child component
248
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'a-0' ] ) ;
248
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'a-0' ] ) ;
249
249
250
250
// Unsetting the subscriber prop should reset subscribed values
251
251
ReactNoop . render (
252
252
< Subscription source = { observableB } > { render } </ Subscription > ,
253
253
) ;
254
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'b-0' ] ) ;
254
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'b-0' ] ) ;
255
255
256
256
// Updates to the old subscribable should not re-render the child component
257
257
observableA . next ( 'a-1' ) ;
258
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ ] ) ;
258
+ expect ( ReactNoop ) . toFlushAndYield ( [ ] ) ;
259
259
260
260
// Updates to the bew subscribable should re-render the child component
261
261
observableB . next ( 'b-1' ) ;
262
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'b-1' ] ) ;
262
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'b-1' ] ) ;
263
263
} ) ;
264
264
265
265
it ( 'should ignore values emitted by a new subscribable until the commit phase' , ( ) => {
@@ -315,12 +315,12 @@ describe('createSubscription', () => {
315
315
const observableB = createBehaviorSubject ( 'b-0' ) ;
316
316
317
317
ReactNoop . render ( < Parent observed = { observableA } /> ) ;
318
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Subscriber: a-0' , 'Child: a-0' ] ) ;
318
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'Subscriber: a-0' , 'Child: a-0' ] ) ;
319
319
expect ( log ) . toEqual ( [ 'Parent.componentDidMount' ] ) ;
320
320
321
321
// Start React update, but don't finish
322
322
ReactNoop . render ( < Parent observed = { observableB } /> ) ;
323
- ReactNoop . flushThrough ( [ 'Subscriber: b-0' ] ) ;
323
+ expect ( ReactNoop ) . toFlushAndYieldThrough ( [ 'Subscriber: b-0' ] ) ;
324
324
expect ( log ) . toEqual ( [ 'Parent.componentDidMount' ] ) ;
325
325
326
326
// Emit some updates from the uncommitted subscribable
@@ -335,7 +335,7 @@ describe('createSubscription', () => {
335
335
// We expect the last emitted update to be rendered (because of the commit phase value check)
336
336
// But the intermediate ones should be ignored,
337
337
// And the final rendered output should be the higher-priority observable.
338
- expect ( ReactNoop . flush ( ) ) . toEqual ( [
338
+ expect ( ReactNoop ) . toFlushAndYield ( [
339
339
'Child: b-0' ,
340
340
'Subscriber: b-3' ,
341
341
'Child: b-3' ,
@@ -402,12 +402,12 @@ describe('createSubscription', () => {
402
402
const observableB = createBehaviorSubject ( 'b-0' ) ;
403
403
404
404
ReactNoop . render ( < Parent observed = { observableA } /> ) ;
405
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ 'Subscriber: a-0' , 'Child: a-0' ] ) ;
405
+ expect ( ReactNoop ) . toFlushAndYield ( [ 'Subscriber: a-0' , 'Child: a-0' ] ) ;
406
406
expect ( log ) . toEqual ( [ 'Parent.componentDidMount' ] ) ;
407
407
408
408
// Start React update, but don't finish
409
409
ReactNoop . render ( < Parent observed = { observableB } /> ) ;
410
- ReactNoop . flushThrough ( [ 'Subscriber: b-0' ] ) ;
410
+ expect ( ReactNoop ) . toFlushAndYieldThrough ( [ 'Subscriber: b-0' ] ) ;
411
411
expect ( log ) . toEqual ( [ 'Parent.componentDidMount' ] ) ;
412
412
413
413
// Emit some updates from the old subscribable
@@ -420,7 +420,7 @@ describe('createSubscription', () => {
420
420
// Flush everything and ensure that the correct subscribable is used
421
421
// We expect the new subscribable to finish rendering,
422
422
// But then the updated values from the old subscribable should be used.
423
- expect ( ReactNoop . flush ( ) ) . toEqual ( [
423
+ expect ( ReactNoop ) . toFlushAndYield ( [
424
424
'Child: b-0' ,
425
425
'Subscriber: a-2' ,
426
426
'Child: a-2' ,
@@ -433,7 +433,7 @@ describe('createSubscription', () => {
433
433
434
434
// Updates from the new subscribable should be ignored.
435
435
observableB . next ( 'b-1' ) ;
436
- expect ( ReactNoop . flush ( ) ) . toEqual ( [ ] ) ;
436
+ expect ( ReactNoop ) . toFlushAndYield ( [ ] ) ;
437
437
expect ( log ) . toEqual ( [
438
438
'Parent.componentDidMount' ,
439
439
'Parent.componentDidUpdate' ,
@@ -479,7 +479,7 @@ describe('createSubscription', () => {
479
479
< Subscription source = { observable } > { value => null } </ Subscription > ,
480
480
) ;
481
481
482
- expect ( ReactNoop . flush ) . toThrow (
482
+ expect ( ReactNoop ) . toFlushAndThrow (
483
483
'A subscription must return an unsubscribe function.' ,
484
484
) ;
485
485
} ) ;
0 commit comments