-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚀 Feature: Allow hooks to easily set "allowUncaught" flag #1985
Comments
…ha#1985). Move some tests into `test/logger-legacy.test.js`
Per-test or per-suite support for |
I could also really use this right now. |
👍 |
1 similar comment
👍 |
I'm currently setting this on the runner and it works great: mocha.setup(...)
requireAllZeTests()
const runner = mocha.run()
runner.allowUncaught = true |
Related: #1801 |
@spalger has a workaround, and here's another: beforeEach(function () {
this.runnable().allowUncaught = true;
});
it('should be uncaught', function () {
throw new Error();
}); It's not possible to have |
I'm calling this a "bug" insofar as it's a "missing feature". However, I don't have enough understanding of the use case(s) for |
@boneskull I use 'stop on uncaught errors' to automatically stop execution so I can debug a failing test where the exception occurs, with all local variables intact. It's quite helpful. |
@qrohlf What I was trying to get to was "why is this only a browser thing"? |
@boneskull woops, missed that dimension to your question. I agree that |
That would seem reasonable 😄, but there's some reason the intent of the feature was limited to browsers. Basically someone needs to get to the bottom of it by inspecting issues and/or changeset history. |
…ha#1985). Move some tests into `test/logger-legacy.test.js`
…ha#1985). Move some tests into `test/logger-legacy.test.js`
…ha#1985). Move some tests into `test/logger-legacy.test.js`
…ha#1985). Move some tests into `test/logger-legacy.test.js`
…ha#1985). Move some tests into `test/logger-legacy.test.js`
…ha#1985). Move some tests into `test/logger-legacy.test.js`
allowUncaught
anywhere.
I believe it is possible to set this flag from within a test, but not without some code changes. Basically the result should be: it('should set allowUncaught', function () {
this.allowUncaught();
throw new Error('boom crash exit process');
}); |
Both
suite.allowUncaught
andtest.allowUncaught
are completely ignored by themocha.Runner
instance 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.allowUncaught
is pretty naive, but the secondtest.allowUncaught
check 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
--allowUncaught
CLI option also appears to be completely broken right now. My use-case is slightly different, however, since I only want to setallowUncaught
totrue
for some test suites (not all).The text was updated successfully, but these errors were encountered: