Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Fix this.skip() async calls (#3745)

Juerg Bf1662ac98e81
diff --git a/lib/runner.js b/lib/runner.js
index fc69a687..541506e1 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -781,6 +781,9 @@ Runner.prototype.runSuite = function(suite, fn) {
* @private
*/
Runner.prototype.uncaught = function(err) {
+ if (err instanceof Pending) {
+ return;
+ }
if (err) {
debug('uncaught exception %O', err);
} else {
diff --git a/test/integration/fixtures/pending/skip-async-before-hooks.fixture.js b/test/integration/fixtures/pending/skip-async-before-hooks.fixture.js
index 113fef5f..7afd6bc6 100644
--- a/test/integration/fixtures/pending/skip-async-before-hooks.fixture.js
+++ b/test/integration/fixtures/pending/skip-async-before-hooks.fixture.js
@@ -14,8 +14,7 @@ describe('outer suite', function () {
console.log('inner before');
var self = this;
setTimeout(function () {
- self.skip();
- done();
+ self.skip(); // done() is not required
}, 0);
});
diff --git a/test/integration/fixtures/pending/skip-async-before-nested.fixture.js b/test/integration/fixtures/pending/skip-async-before-nested.fixture.js
index 8bab69c3..80a8e72b 100644
--- a/test/integration/fixtures/pending/skip-async-before-nested.fixture.js
+++ b/test/integration/fixtures/pending/skip-async-before-nested.fixture.js
@@ -2,8 +2,7 @@ describe('skip in before with nested describes', function () {
before(function (done) {
var self = this;
setTimeout(function () {
- self.skip();
- done();
+ self.skip(); // done() is not required
}, 0);
});
diff --git a/test/integration/fixtures/pending/skip-async-before.fixture.js b/test/integration/fixtures/pending/skip-async-before.fixture.js
index 5e47bf7b..99266129 100644
--- a/test/integration/fixtures/pending/skip-async-before.fixture.js
+++ b/test/integration/fixtures/pending/skip-async-before.fixture.js
@@ -7,7 +7,7 @@ describe('outer describe', function () {
before(function (done) {
var self = this;
setTimeout(function () {
- self.skip();
+ self.skip(); // done() is not required
}, 0);
});
diff --git a/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js b/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js
index a4f4d243..a450e44b 100644
--- a/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js
+++ b/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js
@@ -4,18 +4,17 @@ describe('skip in beforeEach', function () {
beforeEach(function (done) {
var self = this;
setTimeout(function () {
- self.skip();
- done();
+ self.skip(); // done() is not required
}, 0);
});
- it('should skip this test', function () {
+ it('should skip this test-1', function () {
throw new Error('never run this test');
});
- it('should not reach this test', function () {
+ it('should skip this test-2', function () {
throw new Error('never run this test');
});
- it('should not reach this test', function () {
+ it('should skip this test-3', function () {
throw new Error('never run this test');
});
});
diff --git a/test/integration/fixtures/pending/skip-async-spec.fixture.js b/test/integration/fixtures/pending/skip-async-spec.fixture.js
index 00af28ea..571ca5b8 100644
--- a/test/integration/fixtures/pending/skip-async-spec.fixture.js
+++ b/test/integration/fixtures/pending/skip-async-spec.fixture.js
@@ -4,7 +4,7 @@ describe('skip in test', function () {
it('should skip async', function (done) {
var self = this;
setTimeout(function () {
- self.skip();
+ self.skip(); // done() is not required
}, 0);
});
diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.js
index ea8bd4bf..b6a70392 100644
--- a/test/integration/pending.spec.js
+++ b/test/integration/pending.spec.js
@@ -258,18 +258,21 @@ describe('pending', function() {
describe('in beforeEach', function() {
it('should skip all suite specs', function(done) {
- run('pending/skip-async-beforeEach.fixture.js', args, function(
- err,
- res
- ) {
+ var fixture = 'pending/skip-async-beforeEach.fixture.js';
+ run(fixture, args, function(err, res) {
if (err) {
- done(err);
- return;
+ return done(err);
}
- assert.strictEqual(res.stats.pending, 1);
- assert.strictEqual(res.stats.passes, 0);
- assert.strictEqual(res.stats.failures, 1);
- assert.strictEqual(res.code, 1);
+ expect(res, 'to have passed')
+ .and('to have passed test count', 0)
+ .and('to have pending test count', 3)
+ .and(
+ 'to have pending test order',
+ 'should skip this test-1',
+ 'should skip this test-2',
+ 'should skip this test-3'
+ )
+ .and('to have failed test count', 0);
done();
});
});