Skip to content

Commit

Permalink
Merge pull request #1520 from dasilvacontin/fix/1496
Browse files Browse the repository at this point in the history
In .run(fn), check if fn exists before executing the callback, fixes #1496
  • Loading branch information
Travis Jeffery committed Feb 3, 2015
2 parents 0f118d3 + fc2414d commit 1159795
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ test-sort:
--sort \
test/acceptance/sort

test-mocha:
@./bin/mocha \
--reporter $(REPORTER) \
test/mocha

non-tty:
@./bin/mocha \
--reporter dot \
Expand Down
4 changes: 1 addition & 3 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ Mocha.prototype.run = function(fn){
function done(failures) {
if (reporter.done) {
reporter.done(failures, fn);
} else {
fn(failures);
}
} else fn && fn(failures);
}

return runner.run(done);
Expand Down
33 changes: 33 additions & 0 deletions test/mocha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var Mocha = require('../');
var Test = Mocha.Test;

describe('Mocha', function(){
var blankOpts = { reporter: function(){} }; // no output

describe('.run(fn)', function(){
it('should not raise errors if callback was not provided', function(){
var mocha = new Mocha(blankOpts);
mocha.run();
})

it('should execute the callback when complete', function(done) {
var mocha = new Mocha(blankOpts);
mocha.run(function(){
done();
})
})

it('should execute the callback with the number of failures '+
'as parameter', function(done) {
var mocha = new Mocha(blankOpts);
var failingTest = new Test('failing test', function(){
throw new Error('such fail');
});
mocha.suite.addTest(failingTest);
mocha.run(function(failures) {
failures.should.equal(1);
done();
});
})
})
})

0 comments on commit 1159795

Please sign in to comment.