Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested before error using wrong test name in error message #3333

Closed
wants to merge 8 commits into from
Closed
4 changes: 4 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ Runner.prototype.hook = function(name, fn) {
hook.pending = true;
}
} else {
if (!self.suite.bail()) {
// set the current test to the next one to run so the error message is correct
hook.ctx.currentTest = suite.tests[0];
}
self.failHook(hook, err);

// stop executing hooks, notify callee of hook err
Expand Down
20 changes: 20 additions & 0 deletions test/integration/fixtures/hooks/after-nested-hook-error.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

describe('spec 1', function () {
it('should not blame me', function () {
console.log('test 1');
});
describe('nested 1', function () {
after(function() {
throw new Error('Nested before hook error');
});
it('blames me', function () {
console.log('test 2');
});
});
describe('nested 2', function() {
it('should not blame me either', function() {
console.log('test 3');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

describe('spec 1', function () {
it('should not blame me', function () {
console.log('test 1');
});
describe('nested 1', function () {
before(function() {
throw new Error('Nested before hook error');
});
it('blames me', function () {
console.log('test 2');
});
});
});
27 changes: 26 additions & 1 deletion test/integration/hook-err.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ describe('hook error handling', function() {
describe('before hook error tip', function() {
before(run('hooks/before-hook-error-tip.fixture.js', onlyErrorTitle()));
it('should verify results', function() {
expect(lines, 'to equal', ['1) spec 2', '"before all" hook:']);
expect(lines, 'to equal', [
'1) spec 2',
'"before all" hook for "skipped":'
]);
});
});

describe('nested before hook error', function() {
before(run('hooks/before-nested-hook-error.fixture.js', onlyErrorTitle()));
it('should verify results', function() {
expect(lines, 'to equal', [
'1) spec 1',
'nested 1',
'"before all" hook for "blames me":'
]);
});
});

Expand All @@ -35,6 +49,17 @@ describe('hook error handling', function() {
});
});

describe('nested after hook error', function() {
before(run('hooks/after-nested-hook-error.fixture.js', onlyErrorTitle()));
it('should verify results', function() {
expect(lines, 'to equal', [
'1) spec 1',
'nested 1',
'"after all" hook for "blames me":'
]);
});
});

describe('after each hook error', function() {
before(run('hooks/afterEach-hook-error.fixture.js'));
it('should verify results', function() {
Expand Down