Skip to content

Commit

Permalink
feat(zone.js): include zone name when sync-test zone reports tasks
Browse files Browse the repository at this point in the history
The sync-test zone is used in e.g. `describe` to raise an error when
there is asynchronous code scheduled in describe blocks. This commit
includes the zone name in such thrown errors to allow for us to include
the jasmine describe name in the error. This will be wired up in the
jasmine zonejs patches separately.
  • Loading branch information
devversion committed Jul 18, 2022
1 parent c7b1bb1 commit 72c2567
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/zone.js/lib/zone-spec/sync-test.ts
Expand Up @@ -21,7 +21,7 @@ class SyncTestZoneSpec implements ZoneSpec {
switch (task.type) {
case 'microTask':
case 'macroTask':
throw new Error(`Cannot call ${task.source} from within a sync test.`);
throw new Error(`Cannot call ${task.source} from within a sync test (${this.name}).`);
case 'eventTask':
task = delegate.scheduleTask(target, task);
break;
Expand Down
8 changes: 6 additions & 2 deletions packages/zone.js/test/zone-spec/sync-test.spec.ts
Expand Up @@ -22,15 +22,19 @@ describe('SyncTestZoneSpec', () => {
syncTestZone.run(() => {
expect(() => {
Promise.resolve().then(function() {});
}).toThrow(new Error('Cannot call Promise.then from within a sync test.'));
})
.toThrow(new Error(
'Cannot call Promise.then from within a sync test (syncTestZone for name).'));
});
});

it('should fail on setTimeout', () => {
syncTestZone.run(() => {
expect(() => {
setTimeout(() => {}, 100);
}).toThrow(new Error('Cannot call setTimeout from within a sync test.'));
})
.toThrow(
new Error('Cannot call setTimeout from within a sync test (syncTestZone for name).'));
});
});

Expand Down

0 comments on commit 72c2567

Please sign in to comment.