Skip to content

Commit

Permalink
Merge b297091 into 3064d25
Browse files Browse the repository at this point in the history
  • Loading branch information
prust committed Jun 12, 2019
2 parents 3064d25 + b297091 commit 32d6936
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions browser-entry.js
Expand Up @@ -58,8 +58,8 @@ process.removeListener = function(e, fn) {

process.on = function(e, fn) {
if (e === 'uncaughtException') {
global.onerror = function(err, url, line) {
fn(new Error(err + ' (' + url + ':' + line + ')'));
global.onerror = function(msg, url, line, col, err) {
fn(err || new Error(msg + ' (' + url + ':' + line + ')'));
return !mocha.allowUncaught;
};
uncaughtExceptionHandlers.push(fn);
Expand Down
34 changes: 34 additions & 0 deletions test/unit/throw.spec.js
Expand Up @@ -2,6 +2,7 @@

/* eslint no-throw-literal: off */

var sinon = require('sinon');
var Mocha = require('../../lib/mocha');
var Suite = Mocha.Suite;
var Test = Mocha.Test;
Expand All @@ -13,11 +14,13 @@ var STATE_FAILED = Runnable.constants.STATE_FAILED;
describe('a test that throws', function() {
var suite;
var runner;
var sandbox;
var uncaughtHandlers;

beforeEach(function() {
suite = new Suite('Suite', 'root');
runner = new Runner(suite);
sandbox = sinon.createSandbox();

// see https://github.com/mochajs/mocha/pull/2983#issuecomment-350428522
uncaughtHandlers = process.listeners('uncaughtException') || [];
Expand Down Expand Up @@ -169,4 +172,35 @@ describe('a test that throws', function() {
runner.run();
});
});

describe('stack', function() {
it('should include the stack when throwing async', function(done) {
var test = new Test('im async and throw null async', function(done2) {
process.nextTick(function throwError() {
throw new Error('test error');
});
});
suite.addTest(test);
runner = new Runner(suite);
sandbox.stub(runner, 'fail');

runner.on(EVENT_RUN_END, function() {
try {
expect(runner.fail, 'to have all calls satisfying', [
expect.it('to be a', Runnable),
expect.it('to be an', Error).and('to satisfy', {
message: /test error/i,
stack: /throwError/i,
uncaught: true
})
]).and('was called once');
} catch (err) {
return done(err);
}

done();
});
runner.run();
});
});
});

0 comments on commit 32d6936

Please sign in to comment.