diff --git a/test/zone.spec.js b/test/zone.spec.js index 6e834c5fe..12f00acb1 100644 --- a/test/zone.spec.js +++ b/test/zone.spec.js @@ -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({ diff --git a/zone.js b/zone.js index d143287c0..ad26b225b 100644 --- a/zone.js +++ b/zone.js @@ -18,6 +18,7 @@ Zone.prototype = { constructor: Zone, fork: function (locals) { + this.onZoneCreated(); return new Zone(this, locals); }, @@ -53,6 +54,7 @@ Zone.prototype = { }, onZoneEnter: function () {}, + onZoneCreated: function () {}, onZoneLeave: function () {} };