☕️ Classic, reliable, trusted test framework for Node.js and the browser
refactored Suite#eachTest()
TJ Holowaychuk79579c844adf
diff --git a/lib/suite.js b/lib/suite.jsindex c76c48ac..7220bed2 100644--- a/lib/suite.js+++ b/lib/suite.js@@ -257,11 +257,8 @@ Suite.prototype.total = function(){*/Suite.prototype.eachTest = function(fn){- var self = this;- utils.forEach(self.tests, function(test){- fn(test);- });- utils.forEach(self.suites, function(suite){+ utils.forEach(this.tests, fn);+ utils.forEach(this.suites, function(suite){suite.eachTest(fn);});return this;diff --git a/test/suite.js b/test/suite.jsindex d5b664cb..ad5ea668 100644--- a/test/suite.js+++ b/test/suite.js@@ -257,12 +257,10 @@ describe('Suite', function(){describe('when there are no nested suites or tests', function(){it('should return 0', function(){- var counter = 0;- function fn(){- counter++;- }+ var n = 0;+ function fn(){ n++; }this.suite.eachTest(fn);- counter.should.equal(0);+ n.should.equal(0);});});@@ -271,28 +269,24 @@ describe('Suite', function(){this.suite.addTest(new Test('a child test'));this.suite.addTest(new Test('another child test'));- var counter = 0;- function fn(){- counter++;- }+ var n = 0;+ function fn(){ n++; }this.suite.eachTest(fn);- counter.should.equal(2);+ n.should.equal(2);});});describe('when there are several levels of nested suites', function(){it('should return the number', function(){this.suite.addTest(new Test('a child test'));- var suite = (new Suite('a child suite'));+ var suite = new Suite('a child suite');suite.addTest(new Test('a test in a child suite'));this.suite.addSuite(suite);- var counter = 0;- function fn(){- counter++;- }+ var n = 0;+ function fn(){ n++; }this.suite.eachTest(fn);- counter.should.equal(2);+ n.should.equal(2);});});