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

Commit

Permalink
feat: add onZoneCreated hook
Browse files Browse the repository at this point in the history
  • Loading branch information
btford committed Mar 29, 2014
1 parent 7acebca commit f7badb6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/zone.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,40 @@ describe('Zone.patch', function () {
}).toThrow();
});

it('should fire onZoneCreeated when a zone is forked', function () {
var createdSpy = jasmine.createSpy();
var counter = 0;
var myZone = zone.fork({
onZoneCreated: function () {
counter += 1;
},
onZoneLeave: function () {
counter -= 1;
}
});

myZone.run(function () {

expect(counter).toBe(0);

setTimeout(function () {
expect(counter).toBe(2);
}, 0);
expect(counter).toBe(1);

setTimeout(function () {
expect(counter).toBe(1);
setTimeout(function () {}, 0);
expect(counter).toBe(2);
}, 0);
expect(counter).toBe(2);

jasmine.Clock.tick(1);

expect(counter).toBe(0);
});
});

it('should fire onError if a function run by a zone throws', function () {
var errorSpy = jasmine.createSpy();
var myZone = zone.fork({
Expand Down
2 changes: 2 additions & 0 deletions zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Zone.prototype = {
constructor: Zone,

fork: function (locals) {
this.onZoneCreated();
return new Zone(this, locals);
},

Expand Down Expand Up @@ -53,6 +54,7 @@ Zone.prototype = {
},

onZoneEnter: function () {},
onZoneCreated: function () {},
onZoneLeave: function () {}
};

Expand Down

0 comments on commit f7badb6

Please sign in to comment.