Skip to content

Commit ac93711

Browse files
committed
test(NgZone): more tests modified
1 parent 5e61bdb commit ac93711

File tree

1 file changed

+41
-9
lines changed

1 file changed

+41
-9
lines changed

test/core/zone_spec.dart

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,22 @@ void main() {
185185
expect(log.result()).toEqual('onTurnStart; run; scheduleMicrotask; onTurnDone; onTurnStart; onTurnAsync; onTurnDone');
186186
}));
187187

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();
188201

202+
expect(log.result()).toEqual('onTurnStart; run; scheduleMicrotask; onTurnDone; onTurnStart; onTurnAsync; onTurnDone');
203+
}));
189204

190205
it('should call onTurnDone once after a turn', async((Logger log) {
191206
zone.run(() {
@@ -201,12 +216,20 @@ void main() {
201216
}));
202217

203218

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+
};
206229
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;
210233
}
211234
log('onTurnDone');
212235
};
@@ -227,7 +250,7 @@ void main() {
227250
});
228251
microLeap();
229252

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');
231254
}));
232255

233256

@@ -254,7 +277,8 @@ void main() {
254277
}));
255278

256279

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) {
258282
zone.run(() {
259283
log('run start');
260284
scheduleMicrotask(() {
@@ -311,6 +335,10 @@ void main() {
311335

312336
it('should support assertInZone', async(() {
313337
var calls = '';
338+
zone.onTurnStart = () {
339+
zone.assertInZone();
340+
calls += 'start;';
341+
};
314342
zone.onTurnDone = () {
315343
zone.assertInZone();
316344
calls += 'done;';
@@ -325,7 +353,7 @@ void main() {
325353
});
326354

327355
microLeap();
328-
expect(calls).toEqual('sync;async;done;');
356+
expect(calls).toEqual('start;sync;async;done;');
329357
}));
330358

331359
it('should throw outside of the zone', () {
@@ -338,6 +366,10 @@ void main() {
338366

339367
it('should support assertInTurn', async(() {
340368
var calls = '';
369+
zone.onTurnStart = () {
370+
zone.assertInZone();
371+
calls += 'start;';
372+
};
341373
zone.onTurnDone = () {
342374
calls += 'done;';
343375
zone.assertInTurn();
@@ -352,7 +384,7 @@ void main() {
352384
});
353385

354386
microLeap();
355-
expect(calls).toEqual('sync;async;done;');
387+
expect(calls).toEqual('start;sync;async;done;');
356388
}));
357389

358390

0 commit comments

Comments
 (0)