diff --git a/lib/zone.ts b/lib/zone.ts index 79c70e11c..a8abe4e5b 100644 --- a/lib/zone.ts +++ b/lib/zone.ts @@ -1073,6 +1073,7 @@ const Zone: ZoneType = (function(global: any) { this._hasTaskZS.onHasTask( this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty); } catch (err) { + this.handleError(targetZone, err); } } diff --git a/test/common/zone.spec.ts b/test/common/zone.spec.ts index e4533cbd4..95cd0219a 100644 --- a/test/common/zone.spec.ts +++ b/test/common/zone.spec.ts @@ -382,6 +382,25 @@ describe('Zone', function() { JSON.stringify(macro); }).not.toThrow(); }); + + it('should call onHandleError callback when zoneSpec onHasTask throw error', () => { + const spy = jasmine.createSpy('error'); + const hasTaskZone = Zone.current.fork({ + name: 'hasTask', + onHasTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, + hasTasState: HasTaskState) => { + throw new Error('onHasTask Error'); + }, + onHandleError: + (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, error: Error) => { + spy(error.message); + return delegate.handleError(targetZone, error); + } + }); + + const microTask = hasTaskZone.scheduleMicroTask('test', () => {}, null, () => {}); + expect(spy).toHaveBeenCalledWith('onHasTask Error'); + }); }); });