Both suite.allowUncaught and test.allowUncaught are completely ignored by the mocha.Runner instance being used at any time. (See code: https://github.com/mochajs/mocha/blob/master/lib/runner.js#L413-L416).
if (this.allowUncaught) {
test.allowUncaught = true;
return test.run(fn);
}
Which really should be something like:
if (this.allowUncaught || test.parent.allowUncaught || test.allowUncaught) {
test.allowUncaught = true;
return test.run(fn);
}
Now I'm not really sure the best way to traverse up the tree of suites to find all of the parents so the test.parent.allowUncaught is pretty naive, but the second test.allowUncaught check allows for a (somewhat) elegant work-around:
describe('Anything', function () {
this.on('test', function (test) {
test.allowUncaught = true;
});
});
The super-hack work-around until I have the time to make a pull-request for this is:
//
// This is an awful and fragile hack that
// needs to be changed ASAP.
//
var _runTest = mocha.Runner.prototype.runTest;
mocha.Runner.prototype.runTest = function () {
this.allowUncaught = true;
_runTest.apply(this, arguments);
};
describe('Anything', function () {
after(function () {
mocha.Runner.prototype.runTest = _runTest;
});
});
Worth noting that the --allowUncaught CLI option also appears to be completely broken right now. My use-case is slightly different, however, since I only want to set allowUncaught to true for some test suites (not all).
Both
suite.allowUncaughtandtest.allowUncaughtare completely ignored by themocha.Runnerinstance being used at any time. (See code: https://github.com/mochajs/mocha/blob/master/lib/runner.js#L413-L416).Which really should be something like:
Now I'm not really sure the best way to traverse up the tree of suites to find all of the parents so the
test.parent.allowUncaughtis pretty naive, but the secondtest.allowUncaughtcheck allows for a (somewhat) elegant work-around:The super-hack work-around until I have the time to make a pull-request for this is:
Worth noting that the
--allowUncaughtCLI option also appears to be completely broken right now. My use-case is slightly different, however, since I only want to setallowUncaughttotruefor some test suites (not all).