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

Commit f514c11

Browse files
JiaLiPassionmhevery
authored andcommitted
fix(error): fix #706, handleError when onHasTask throw error (#709)
1 parent 44d507d commit f514c11

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

lib/zone.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,7 @@ const Zone: ZoneType = (function(global: any) {
10911091
this._hasTaskZS.onHasTask(
10921092
this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
10931093
} catch (err) {
1094+
this.handleError(targetZone, err);
10941095
}
10951096
}
10961097

test/common/zone.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,25 @@ describe('Zone', function() {
394394
JSON.stringify(macro);
395395
}).not.toThrow();
396396
});
397+
398+
it('should call onHandleError callback when zoneSpec onHasTask throw error', () => {
399+
const spy = jasmine.createSpy('error');
400+
const hasTaskZone = Zone.current.fork({
401+
name: 'hasTask',
402+
onHasTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone,
403+
hasTasState: HasTaskState) => {
404+
throw new Error('onHasTask Error');
405+
},
406+
onHandleError:
407+
(delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: Error) => {
408+
spy(error.message);
409+
return delegate.handleError(targetZone, error);
410+
}
411+
});
412+
413+
const microTask = hasTaskZone.scheduleMicroTask('test', () => {}, null, () => {});
414+
expect(spy).toHaveBeenCalledWith('onHasTask Error');
415+
});
397416
});
398417
});
399418

0 commit comments

Comments
 (0)