diff --git a/counting-zone.js b/counting-zone.js
index 906ecc863..0a83fece0 100644
--- a/counting-zone.js
+++ b/counting-zone.js
@@ -1,21 +1,22 @@
/*
* See example/counting.html
*/
-zone.countingZone = {
+Zone.countingZone = {
'-onZoneCreated': function () {
- zone.countingZone.counter += 1;
+ Zone.countingZone.counter += 1;
},
'+onZoneLeave': function () {
- zone.countingZone.counter -= 1;
- if (zone.countingZone.counter === 0) {
+ Zone.countingZone.counter -= 1;
+ if (Zone.countingZone.counter <= 0) {
+ Zone.countingZone.counter = 0;
this.onFlush();
}
},
- reset: function () {
- zone.countingZone.counter = 0;
+ '-run': function () {
+ Zone.countingZone.counter = 0;
},
counter: function () {
- return zone.countingZone.counter;
+ return Zone.countingZone.counter;
},
onFlush: function () {}
};
diff --git a/example/counting.html b/example/counting.html
index d79d96c5d..caaffc07b 100644
--- a/example/counting.html
+++ b/example/counting.html
@@ -26,22 +26,22 @@
Counting Pending Tasks
/*
* Zone that counts pending async tasks
*/
- var myCountingZone = zone.fork(zone.countingZone).fork({
+ var myCountingZone = zone.fork(Zone.countingZone).fork({
'+onZoneCreated': function () {
- zone.countingZone.start || (zone.countingZone.start = Date.now());
+ Zone.countingZone.start || (Zone.countingZone.start = Date.now());
this.print();
},
'-onZoneLeave': function (delegate) {
this.print();
},
'+reset': function (delegate) {
- zone.countingZone.start = 0;
+ Zone.countingZone.start = 0;
},
print: function () {
counter = this.counter();
output.innerHTML = counter ?
'pending task count: ' + counter :
- ' DONE! ' + (Date.now() - zone.countingZone.start)/1000 + 's';
+ ' DONE! ' + (Date.now() - Zone.countingZone.start)/1000 + 's';
}
});
diff --git a/test/counting-zone.spec.js b/test/counting-zone.spec.js
new file mode 100644
index 000000000..95948f3c7
--- /dev/null
+++ b/test/counting-zone.spec.js
@@ -0,0 +1,34 @@
+'use strict';
+
+
+describe('Zone.countingZone', function () {
+ var flushSpy = jasmine.createSpy('flush'),
+ countingZone = zone.fork(Zone.countingZone).fork({
+ onFlush: flushSpy
+ });
+
+ beforeEach(function () {
+ jasmine.Clock.useMock();
+ flushSpy.reset();
+ });
+
+ it('should flush at the end of a run', function () {
+ countingZone.run(function () {});
+ expect(flushSpy).toHaveBeenCalled();
+ expect(countingZone.counter()).toBe(0);
+ });
+
+ it('should work', function () {
+ countingZone.run(function () {
+
+ setTimeout(function () {}, 0);
+ expect(countingZone.counter()).toBe(1);
+
+ //jasmine.Clock.tick(0);
+
+ //expect(countingZone.counter()).toBe(0);
+ });
+
+ //jasmine.Clock.tick(0);
+ });
+});