Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fix an error when fn===undefined (#3580)

Svetlanaee6d5761f8d2
diff --git a/lib/mocha.js b/lib/mocha.js
index d2ded3bf..f92cc173 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -776,10 +776,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 82ba0e14..e17fe2cf 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);