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

fix emit "pending" when running pending test #1707

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ Runnable.prototype.run = function(fn){
, finished
, emitted;

// Runner expects to catch an instance of Pending if a pending test is ran
if (this.pending)
throw new Pending();

// Some times the ctx exists but it is not runnable
if (ctx && ctx.runnable) ctx.runnable(this);

Expand Down Expand Up @@ -253,11 +257,7 @@ Runnable.prototype.run = function(fn){

// sync or promise-returning
try {
if (this.pending) {
done();
} else {
callFn(this.fn);
}
callFn(this.fn);
} catch (err) {
done(utils.getError(err));
}
Expand Down
35 changes: 35 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,39 @@ describe('Runner', function(){
});
});
});

describe('.run', function(){
it('should emit "pending" for each pending test', function(done){
var pendingCount = 0;

var pendingTest = new Test('a pending test', function (){});
pendingTest.pending = true;

var skippedTest = new Test('a test that will be skipped', function(){
this.skip();
});

var otherPendingTest = new Test('a test that will be marked as pending',
function(){});

suite.addTest(pendingTest);
suite.addTest(skippedTest);
suite.addTest(otherPendingTest);

runner.on('test', function (test) {
if (test === otherPendingTest)
otherPendingTest.pending = true;
});

runner.on('pending', function () {
pendingCount++;
});

runner.run(function (){
pendingCount.should.equal(3);
done();
});
})
})

});