Skip to content

Commit

Permalink
Decorate failed hook titles with test title
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Jul 5, 2015
1 parent 39ce95f commit 864ec20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/runner.js
Expand Up @@ -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');
Expand Down
13 changes: 13 additions & 0 deletions test/runner.js
Expand Up @@ -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){
Expand Down

0 comments on commit 864ec20

Please sign in to comment.