☕️ Classic, reliable, trusted test framework for Node.js and the browser
fixes #1496, in Mocha.run(fn), check if fn exists before executing it, added tests too
David da Silvafc2414d3d291
diff --git a/Makefile b/Makefileindex 72c4814c..f7542a11 100644--- a/Makefile+++ b/Makefile@@ -164,6 +164,11 @@ test-sort:--sort \test/acceptance/sort+test-mocha:+ @./bin/mocha \+ --reporter $(REPORTER) \+ test/mocha+non-tty:@./bin/mocha \--reporter dot \diff --git a/lib/mocha.js b/lib/mocha.jsindex 27b45021..fa05ce59 100644--- a/lib/mocha.js+++ b/lib/mocha.js@@ -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);diff --git a/test/mocha.js b/test/mocha.jsnew file mode 100644index 00000000..46411fc1--- /dev/null+++ b/test/mocha.js@@ -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();+ });+ })+ })+})