From 863fb5c50371dfc63d0f183ed816c7ba54d91fe8 Mon Sep 17 00:00:00 2001 From: Vikram Subramanian Date: Wed, 15 Feb 2017 14:58:17 -0800 Subject: [PATCH] fix(zonespec): don't throw and exception when setInterval is called within a async test zone --- lib/zone-spec/async-test.ts | 9 --------- test/zone-spec/async-test.spec.ts | 11 ++++++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/lib/zone-spec/async-test.ts b/lib/zone-spec/async-test.ts index fdeb56a95..dfcfa1d41 100644 --- a/lib/zone-spec/async-test.ts +++ b/lib/zone-spec/async-test.ts @@ -61,15 +61,6 @@ class AsyncTestZoneSpec implements ZoneSpec { return false; } - onScheduleTask(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task): Task { - if (task.type == 'macroTask' && task.source == 'setInterval') { - this._failCallback('Cannot use setInterval from within an async zone test.'); - return; - } - - return delegate.scheduleTask(targetZone, task); - } - onHasTask(delegate: ZoneDelegate, current: Zone, target: Zone, hasTaskState: HasTaskState) { delegate.hasTask(target, hasTaskState); if (hasTaskState.change == 'microTask') { diff --git a/test/zone-spec/async-test.spec.ts b/test/zone-spec/async-test.spec.ts index 7f881c237..1e3996787 100644 --- a/test/zone-spec/async-test.spec.ts +++ b/test/zone-spec/async-test.spec.ts @@ -259,21 +259,22 @@ describe('AsyncTestZoneSpec', function() { }); })); - it('should fail if setInterval is used', (done) => { + it('should not fail if setInterval is used and canceled', (done) => { const testZoneSpec = new AsyncTestZoneSpec( () => { - done.fail('expected failCallback to be called'); + done(); }, (err) => { - expect(err).toEqual('Cannot use setInterval from within an async zone test.'); - done(); + done.fail('async zone called failCallback unexpectedly'); }, 'name'); const atz = Zone.current.fork(testZoneSpec); atz.run(function() { - setInterval(() => {}, 100); + let id = setInterval(() => { + clearInterval(id); + }, 100); }); });