diff --git a/lib/runner.js b/lib/runner.js index ba4d7df97c..72e6e1438e 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -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) { diff --git a/test/runner.js b/test/runner.js index 7673a8384e..3026bff0da 100644 --- a/test/runner.js +++ b/test/runner.js @@ -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; @@ -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() {