Skip to content

Commit

Permalink
https://github.com/mochajs/mocha/issues/2302
Browse files Browse the repository at this point in the history
  • Loading branch information
dima117 committed Jun 14, 2016
1 parent e939d8e commit 52481e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/runner.js
Expand Up @@ -287,6 +287,8 @@ Runner.prototype.hook = function(name, fn) {

hook.ctx.currentTest = self.test;

hook.allowUncaught = self.allowUncaught;

self.emit('hook', hook);

if (!hook.listeners('error').length) {
Expand Down
24 changes: 24 additions & 0 deletions test/runner.js
Expand Up @@ -315,6 +315,17 @@ describe('Runner', function(){
});

describe('allowUncaught', function() {
var immediately;

before(function() {
immediately = Runner.immediately;
Runner.immediately = function(fn) { fn(); };
});

after(function() {
Runner.immediately = immediately;
});

it('should allow unhandled errors to propagate through', function(done) {
var newRunner = new Runner(suite);
newRunner.allowUncaught = true;
Expand All @@ -327,6 +338,19 @@ describe('Runner', function(){
fail.should.throw('allow unhandled errors');
done();
});

it('should allow unhandled errors in hooks to propagate through', function(done) {
var runner = new Runner(suite);
runner.allowUncaught = true;
suite.beforeEach(function(){
throw new Error('allow unhandled errors in hooks');
});
function fail() {
runner.hook('beforeEach', function() {});
}
fail.should.throw('allow unhandled errors in hooks');
done();
});
});

describe('stackTrace', function() {
Expand Down

0 comments on commit 52481e1

Please sign in to comment.