☕️ Classic, reliable, trusted test framework for Node.js and the browser
Decorate failed hook titles with test title
Duncan Beevers864ec2077ac8
diff --git a/lib/runner.js b/lib/runner.jsindex f6a8fc24..0e330947 100644--- a/lib/runner.js+++ b/lib/runner.js@@ -245,6 +245,11 @@ Runner.prototype.fail = function(test, err) {* @param {Error} err*/Runner.prototype.failHook = function(hook, err) {+ if (hook.ctx && hook.ctx.currentTest) {+ hook.originalTitle = hook.originalTitle || hook.title;+ hook.title = hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';+ }+this.fail(hook, err);if (this.suite.bail()) {this.emit('end');diff --git a/test/runner.js b/test/runner.jsindex 08a5ce3e..1e023143 100644--- a/test/runner.js+++ b/test/runner.js@@ -275,6 +275,19 @@ describe('Runner', function(){runner.failures.should.equal(2);})+ it('should augment hook title with current test title', function(){+ var hook = {+ title: '"before each" hook',+ ctx: { currentTest: new Test('should behave') }+ };+ runner.failHook(hook, {});+ hook.title.should.equal('"before each" hook for "should behave"');++ hook.ctx.currentTest = new Test('should obey');+ runner.failHook(hook, {});+ hook.title.should.equal('"before each" hook for "should obey"');+ })+it('should emit "fail"', function(done){var hook = {}, err = {};runner.on('fail', function(hook, err){