Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a description with the reason why a test is pending #3324

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Added support for this.skip(reason) in async spec
  • Loading branch information
rdennis committed May 19, 2018
commit 9f64222d85857c01ee49c61fe668fdb64bcca697
8 changes: 6 additions & 2 deletions lib/runnable.js
Original file line number Diff line number Diff line change
@@ -332,8 +332,12 @@ Runnable.prototype.run = function(fn) {
this.resetTimeout();

// allows skip() to be used in an explicit async context
this.skip = function asyncSkip() {
done(new Pending('async skip call'));
this.skip = function asyncSkip(reason) {
if (reason) {
reason = String(reason);
this.reason = reason;
}
done(new Pending(reason || 'async skip call'));
// halt execution. the Runnable will be marked pending
// by the previous call, and the uncaught handler will ignore
// the failure.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

describe('skip in test', function () {
it('should skip async', function (done) {
var self = this;
setTimeout(function () {
self.skip();
}, 50);
});

it('should run other tests in the suite', function () {
// Do nothing
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

describe('skip in test', function () {
it('should skip async', function (done) {
var self = this;
setTimeout(function () {
self.skip('skip reason');
}, 50);
});

it('should run other tests in the suite', function () {
// Do nothing
});
});
36 changes: 36 additions & 0 deletions test/integration/pending.spec.js
Original file line number Diff line number Diff line change
@@ -147,6 +147,42 @@ describe('pending', function() {
done();
});
});

it('should allow a skip reason', function(done) {
run('pending/skip-async-spec-with-reason.fixture.js', args, function(
err,
res
) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 1);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
assert.equal(res.pending[0].reason, 'skip reason');
done();
});
});

it('should allow a skip with no reason to result in no reason property', function(done) {
run('pending/skip-async-spec-with-no-reason.fixture.js', args, function(
err,
res
) {
if (err) {
done(err);
return;
}
assert.equal(res.stats.pending, 1);
assert.equal(res.stats.passes, 1);
assert.equal(res.stats.failures, 0);
assert.equal(res.code, 0);
assert.ok(!res.pending[0].hasOwnProperty('reason'));
done();
});
});
});

describe('in before', function() {