Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
givanse committed Mar 2, 2019
1 parent 5b9633e commit 6e4cbe4
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions test/unit/runner.spec.js
Expand Up @@ -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;
Expand All @@ -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 sync 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() {});
});
});

Expand Down

0 comments on commit 6e4cbe4

Please sign in to comment.