@@ -185,7 +185,22 @@ void main() {
185
185
expect (log.result ()).toEqual ('onTurnStart; run; scheduleMicrotask; onTurnDone; onTurnStart; onTurnAsync; onTurnDone' );
186
186
}));
187
187
188
+ it ('should call onTurnDone for a scheduleMicrotask in onTurnStart triggered by a scheduleMicrotask in run' , async ((Logger log) {
189
+ var ran = false ;
190
+ zone.onTurnStart = () {
191
+ if (! ran) {
192
+ scheduleMicrotask (() { ran = true ; log ('onTurnAsync' ); });
193
+ }
194
+ log ('onTurnStart' );
195
+ };
196
+ zone.run (() {
197
+ scheduleMicrotask (() { log ('scheduleMicrotask' ); });
198
+ log ('run' );
199
+ });
200
+ microLeap ();
188
201
202
+ expect (log.result ()).toEqual ('onTurnStart; run; scheduleMicrotask; onTurnDone; onTurnStart; onTurnAsync; onTurnDone' );
203
+ }));
189
204
190
205
it ('should call onTurnDone once after a turn' , async ((Logger log) {
191
206
zone.run (() {
@@ -201,12 +216,20 @@ void main() {
201
216
}));
202
217
203
218
204
- xit ('should work for Future.value as well' , async ((Logger log) {
205
- var futureRan = false ;
219
+ it ('should work for Future.value as well' , async ((Logger log) {
220
+ var onDoneFutureRan = false ;
221
+ var onStartFutureRan = false ;
222
+ zone.onTurnStart = () {
223
+ if (! onStartFutureRan) {
224
+ new Future .value (null ).then ((_) { log ('onTurnStart future' ); });
225
+ onStartFutureRan = true ;
226
+ }
227
+ log ('onTurnStart' );
228
+ };
206
229
zone.onTurnDone = () {
207
- if (! futureRan ) {
208
- new Future .value (null ).then ((_) { log ('onTurn future' ); });
209
- futureRan = true ;
230
+ if (! onDoneFutureRan ) {
231
+ new Future .value (null ).then ((_) { log ('onTurnDone future' ); });
232
+ onDoneFutureRan = true ;
210
233
}
211
234
log ('onTurnDone' );
212
235
};
@@ -227,7 +250,7 @@ void main() {
227
250
});
228
251
microLeap ();
229
252
230
- expect (log.result ()).toEqual ('run start; run end; future then; future ?; future ?; onTurnDone; onTurn future; onTurnDone' );
253
+ expect (log.result ()).toEqual ('onTurnStart; run start; run end; future then; future ?; future ?; onTurnDone; onTurnStart future; onTurnDone future; onTurnDone' );
231
254
}));
232
255
233
256
@@ -254,7 +277,8 @@ void main() {
254
277
}));
255
278
256
279
257
- it ('should call onTurnDone after each turn in a chain' , async ((Logger log) {
280
+ it ('should call onTurnStart before any turn in the chain and onTurnDone after every turn in a'
281
+ ' chain' , async ((Logger log) {
258
282
zone.run (() {
259
283
log ('run start' );
260
284
scheduleMicrotask (() {
@@ -311,6 +335,10 @@ void main() {
311
335
312
336
it ('should support assertInZone' , async (() {
313
337
var calls = '' ;
338
+ zone.onTurnStart = () {
339
+ zone.assertInZone ();
340
+ calls += 'start;' ;
341
+ };
314
342
zone.onTurnDone = () {
315
343
zone.assertInZone ();
316
344
calls += 'done;' ;
@@ -325,7 +353,7 @@ void main() {
325
353
});
326
354
327
355
microLeap ();
328
- expect (calls).toEqual ('sync;async;done;' );
356
+ expect (calls).toEqual ('start; sync;async;done;' );
329
357
}));
330
358
331
359
it ('should throw outside of the zone' , () {
@@ -338,6 +366,10 @@ void main() {
338
366
339
367
it ('should support assertInTurn' , async (() {
340
368
var calls = '' ;
369
+ zone.onTurnStart = () {
370
+ zone.assertInZone ();
371
+ calls += 'start;' ;
372
+ };
341
373
zone.onTurnDone = () {
342
374
calls += 'done;' ;
343
375
zone.assertInTurn ();
@@ -352,7 +384,7 @@ void main() {
352
384
});
353
385
354
386
microLeap ();
355
- expect (calls).toEqual ('sync;async;done;' );
387
+ expect (calls).toEqual ('start; sync;async;done;' );
356
388
}));
357
389
358
390
0 commit comments