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

Commit

Permalink
fix(error): fix #706, handleError when onHasTask throw error (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
JiaLiPassion authored and mhevery committed Apr 10, 2017
1 parent e422fb1 commit 06d1ac0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ const Zone: ZoneType = (function(global: any) {
this._hasTaskZS.onHasTask(
this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
} catch (err) {
this.handleError(targetZone, err);
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/common/zone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

Expand Down

0 comments on commit 06d1ac0

Please sign in to comment.