From 98d322876b1be1e0e81cd594c716277e33616434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gast=C3=B3n=20I=2E=20Silva?= Date: Sun, 17 Feb 2019 07:08:29 -0800 Subject: [PATCH] PR feedback --- test/unit/runner.spec.js | 64 ++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.js index c80b781946..b24c046d58 100644 --- a/test/unit/runner.spec.js +++ b/test/unit/runner.spec.js @@ -443,19 +443,6 @@ 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() { var newRunner = new Runner(suite); newRunner.allowUncaught = true; @@ -473,37 +460,56 @@ describe('Runner', function() { throw new Error('this error will not propagate'); }); var runner = new Runner(suite); - try { + expect(function() { runner.hook('beforeEach', function() {}); - expect(true, 'to be', true); - } catch (err) { - expect(false, 'to be', true); - } + }, 'not to throw'); }); - it('should allow unhandled errors in sync hooks to propagate through', function() { + it('should allow unhandled errors in sync hooks to propagate through', function(done) { suite.beforeEach(function() { throw new Error('allow unhandled errors in sync hooks'); }); var runner = new Runner(suite); runner.allowUncaught = true; - function throwError() { - runner.hook('beforeEach', function() {}); - } - expect(throwError, 'to throw', 'allow unhandled errors in sync hooks'); + + var EVENT_HOOK_BEGIN = 'hook'; + runner.on(EVENT_HOOK_BEGIN, function(hook) { + var _run = hook.run; + hook.run = function() { + function throwError() { + _run.call(hook); + } + var expected = 'allow unhandled errors in async hooks'; + expect(throwError, 'to throw', expected); + done(); + }; + }); + + runner.hook('beforeEach', function() {}); }); - it('async - should allow unhandled errors in hooks to propagate through', function() { - // having `done` triggers the async path + it('async - should allow unhandled errors in hooks to propagate through', function(done) { + // having the `done` argument triggers the async path suite.beforeEach(function(done) { throw new Error('allow unhandled errors in async hooks'); }); var runner = new Runner(suite); runner.allowUncaught = true; - function throwError() { - runner.hook('beforeEach', function() {}); - } - expect(throwError, 'to throw', 'allow unhandled errors in async hooks'); + + var EVENT_HOOK_BEGIN = 'hook'; + runner.on(EVENT_HOOK_BEGIN, function(hook) { + var _run = hook.run; + hook.run = function() { + function throwError() { + _run.call(hook, function() {}); + } + var expected = 'allow unhandled errors in async hooks'; + expect(throwError, 'to throw', expected); + done(); + }; + }); + + runner.hook('beforeEach', function() {}); }); });