Skip to content

Commit 72c2567

Browse files
committed
feat(zone.js): include zone name when sync-test zone reports tasks
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.
1 parent c7b1bb1 commit 72c2567

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

packages/zone.js/lib/zone-spec/sync-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SyncTestZoneSpec implements ZoneSpec {
2121
switch (task.type) {
2222
case 'microTask':
2323
case 'macroTask':
24-
throw new Error(`Cannot call ${task.source} from within a sync test.`);
24+
throw new Error(`Cannot call ${task.source} from within a sync test (${this.name}).`);
2525
case 'eventTask':
2626
task = delegate.scheduleTask(target, task);
2727
break;

packages/zone.js/test/zone-spec/sync-test.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ describe('SyncTestZoneSpec', () => {
2222
syncTestZone.run(() => {
2323
expect(() => {
2424
Promise.resolve().then(function() {});
25-
}).toThrow(new Error('Cannot call Promise.then from within a sync test.'));
25+
})
26+
.toThrow(new Error(
27+
'Cannot call Promise.then from within a sync test (syncTestZone for name).'));
2628
});
2729
});
2830

2931
it('should fail on setTimeout', () => {
3032
syncTestZone.run(() => {
3133
expect(() => {
3234
setTimeout(() => {}, 100);
33-
}).toThrow(new Error('Cannot call setTimeout from within a sync test.'));
35+
})
36+
.toThrow(
37+
new Error('Cannot call setTimeout from within a sync test (syncTestZone for name).'));
3438
});
3539
});
3640

0 commit comments

Comments
 (0)