Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

fix: fix uncaught TypeError if error occurs on next tick, closes #2315 (#2439)

Dmitry Sorinf1ac5485f19c
diff --git a/lib/runner.js b/lib/runner.js
index 22907f57..145d9903 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -420,6 +420,9 @@ Runner.prototype.runTest = function(fn) {
var self = this;
var test = this.test;
+ if (!test) {
+ return;
+ }
if (this.asyncOnly) {
test.asyncOnly = true;
}
diff --git a/test/integration/fixtures/regression/issue-2315.js b/test/integration/fixtures/regression/issue-2315.js
new file mode 100644
index 00000000..d3d1f936
--- /dev/null
+++ b/test/integration/fixtures/regression/issue-2315.js
@@ -0,0 +1,7 @@
+describe('issue-2315: cannot read property currentRetry of undefined', function () {
+ before(function () {
+ require('http').createServer().listen(1);
+ });
+
+ it('something', function () {});
+});
diff --git a/test/integration/regression.spec.js b/test/integration/regression.spec.js
index f9f96d31..f2a435a3 100644
--- a/test/integration/regression.spec.js
+++ b/test/integration/regression.spec.js
@@ -1,4 +1,4 @@
-var assert = require('assert');
+var assert = require('assert');
var fs = require('fs');
var path = require('path');
var run = require('./helpers').runMocha;
@@ -62,6 +62,17 @@ describe('regressions', function() {
});
});
+ it('issue-2315: cannot read property currentRetry of undefined', function (done) {
+ runJSON('regression/issue-2315.js', [], function(err, res) {
+ assert(!err);
+ assert.equal(res.stats.pending, 0);
+ assert.equal(res.stats.passes, 0);
+ assert.equal(res.stats.failures, 1);
+ assert.equal(res.code, 1);
+ done();
+ });
+ });
+
it('issue-2406: should run nested describe.only suites', function(done) {
this.timeout(2000);
runJSON('regression/issue-2406.fixture.js', [], function(err, res) {