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 44d507d commit f514c11
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 @@ -1091,6 +1091,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 @@ -394,6 +394,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 f514c11

Please sign in to comment.