diff --git a/lib/mocha.js b/lib/mocha.js index cce2bb9b2f..66adf6423d 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -781,10 +781,11 @@ Mocha.prototype.run = function(fn) { exports.reporters.Base.hideDiff = options.hideDiff; function done(failures) { + fn = fn || function fn() {}; if (reporter.done) { reporter.done(failures, fn); } else { - fn && fn(failures); + fn(failures); } } diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.js index 2511b1204d..00a5f8eac0 100644 --- a/test/unit/mocha.spec.js +++ b/test/unit/mocha.spec.js @@ -56,6 +56,20 @@ describe('Mocha', function() { }); }); + describe('.reporter("xunit").run(fn)', function() { + it('should not raise errors if callback was not provided', function() { + var mocha = new Mocha(); + expect(function() { + try { + mocha.reporter('xunit').run(); + } catch (e) { + console.log(e); + expect.fail(e.message); + } + }, 'not to throw'); + }); + }); + describe('.addFile()', function() { it('should add the given file to the files array', function() { var mocha = new Mocha(opts);