Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit c07560f

Browse files
vikermanmhevery
authored andcommitted
fix(zonespec): don't throw and exception when setInterval is called within a async test zone (#641)
1 parent 12ecc02 commit c07560f

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

Diff for: lib/zone-spec/async-test.ts

-9
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ class AsyncTestZoneSpec implements ZoneSpec {
6161
return false;
6262
}
6363

64-
onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task {
65-
if (task.type == 'macroTask' && task.source == 'setInterval') {
66-
this._failCallback('Cannot use setInterval from within an async zone test.');
67-
return;
68-
}
69-
70-
return delegate.scheduleTask(targetZone, task);
71-
}
72-
7364
onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) {
7465
delegate.hasTask(target, hasTaskState);
7566
if (hasTaskState.change == 'microTask') {

Diff for: test/zone-spec/async-test.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -259,21 +259,22 @@ describe('AsyncTestZoneSpec', function() {
259259
});
260260
}));
261261

262-
it('should fail if setInterval is used', (done) => {
262+
it('should not fail if setInterval is used and canceled', (done) => {
263263
const testZoneSpec = new AsyncTestZoneSpec(
264264
() => {
265-
done.fail('expected failCallback to be called');
265+
done();
266266
},
267267
(err) => {
268-
expect(err).toEqual('Cannot use setInterval from within an async zone test.');
269-
done();
268+
done.fail('async zone called failCallback unexpectedly');
270269
},
271270
'name');
272271

273272
const atz = Zone.current.fork(testZoneSpec);
274273

275274
atz.run(function() {
276-
setInterval(() => {}, 100);
275+
let id = setInterval(() => {
276+
clearInterval(id);
277+
}, 100);
277278
});
278279
});
279280

0 commit comments

Comments
 (0)