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

Commit

Permalink
fix(zonespec): don't throw and exception when setInterval is called w…
Browse files Browse the repository at this point in the history
…ithin a async test zone (#641)
  • Loading branch information
vikerman authored and mhevery committed Feb 15, 2017
1 parent 12ecc02 commit c07560f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
9 changes: 0 additions & 9 deletions lib/zone-spec/async-test.ts
Expand Up @@ -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') {
Expand Down
11 changes: 6 additions & 5 deletions test/zone-spec/async-test.spec.ts
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit c07560f

Please sign in to comment.