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

Commit

Permalink
fix: throw if a zone does not define an onError hook
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Mar 28, 2014
1 parent bf5b79e commit 3485c1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions test/zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ describe('Zone.patch', function () {
expect(leaveSpy).toHaveBeenCalled();
});

it('should throw if onError is not defined', function () {
expect(function () {
zone.run(throwError);
}).toThrow();
});

it('should fire onError if a function run by a zone throws', function () {
var errorSpy = jasmine.createSpy();
var myZone = zone.fork({
Expand All @@ -180,9 +186,9 @@ describe('Zone.patch', function () {

expect(errorSpy).not.toHaveBeenCalled();

myZone.run(function () {
throw new Error('test');
});
expect(function () {
myZone.run(throwError);
}).not.toThrow();

expect(errorSpy).toHaveBeenCalled();
});
Expand Down Expand Up @@ -222,3 +228,7 @@ describe('Zone.patch', function () {
});

});

function throwError () {
throw new Error();
}
2 changes: 2 additions & 0 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Zone.prototype = {
} catch (e) {
if (zone.onError) {
zone.onError(e);
} else {
throw e;
}
} finally {
this.onZoneLeave();
Expand Down

0 comments on commit 3485c1b

Please sign in to comment.