Skip to content

Commit ac12f2c

Browse files
authored
Browser: fix 'allowUncaught' handling (#4174)
1 parent 2ff1cb2 commit ac12f2c

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

browser-entry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ process.on = function(e, fn) {
6060
if (e === 'uncaughtException') {
6161
global.onerror = function(err, url, line) {
6262
fn(new Error(err + ' (' + url + ':' + line + ')'));
63-
return !mocha.allowUncaught;
63+
return !mocha.options.allowUncaught;
6464
};
6565
uncaughtExceptionHandlers.push(fn);
6666
}

docs/index.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js][] and in
2424
- [javascript API for running tests](#more-information)
2525
- proper exit status for CI support etc
2626
- [auto-detects and disables coloring for non-ttys](#reporters)
27-
- [maps uncaught exceptions to the correct test case](#browser-specific-methods)
2827
- [async test timeout support](#delayed-root-suite)
2928
- [test retry support](#retry-tests)
3029
- [test-specific timeouts](#test-level)
@@ -666,7 +665,7 @@ describe('outer', function() {
666665
});
667666
```
668667

669-
> _Updated in v7.0.0. Skipping a test within an "after all" hook is disallowed and will throw an exception. Use a return statement or other means to abort hook execution._
668+
> _Updated in v7.0.0:_ skipping a test within an "after all" hook is disallowed and will throw an exception. Use a return statement or other means to abort hook execution.
670669
671670
Before Mocha v3.0.0, `this.skip()` was not supported in asynchronous tests and hooks.
672671

@@ -1543,12 +1542,6 @@ Alias: `HTML`, `html`
15431542

15441543
Mocha runs in the browser. Every release of Mocha will have new builds of `./mocha.js` and `./mocha.css` for use in the browser.
15451544

1546-
### Browser-specific methods
1547-
1548-
The following method(s) _only_ function in a browser context:
1549-
1550-
`mocha.allowUncaught()` : If called, uncaught errors will not be absorbed by the error handler.
1551-
15521545
A typical setup might look something like the following, where we call `mocha.setup('bdd')` to use the **BDD** interface before loading the test scripts, running them `onload` with `mocha.run()`.
15531546

15541547
```html
@@ -1600,6 +1593,7 @@ mocha.setup({
16001593

16011594
// Examples of options:
16021595
mocha.setup({
1596+
allowUncaught: true,
16031597
asyncOnly: true,
16041598
bail: true,
16051599
checkLeaks: true,

lib/runner.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,8 @@ Runner.prototype.uncaught = function(err) {
800800
if (err instanceof Pending) {
801801
return;
802802
}
803-
if (this.allowUncaught) {
803+
// browser does not exit script when throwing in global.onerror()
804+
if (this.allowUncaught && !process.browser) {
804805
throw err;
805806
}
806807

test/unit/runner.spec.js

+2
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ describe('Runner', function() {
709709

710710
describe('when allow-uncaught is set to true', function() {
711711
it('should propagate error and throw', function() {
712+
if (process.browser) this.skip();
713+
712714
var err = new Error('should rethrow err');
713715
runner.allowUncaught = true;
714716
expect(

0 commit comments

Comments
 (0)