From 34116d5d67b75fd189637cc773ce550ba956bc36 Mon Sep 17 00:00:00 2001 From: Brian Lalor Date: Sun, 6 Oct 2013 08:42:24 -0400 Subject: [PATCH] Include assertion message as context (close #993) Resolves #991 This expect statement expect("foo", "the foo").to.equal("bar"); now includes "the foo" as context for the failed match. 1) reporter shows reason for failed assertion: the foo + expected - actual +"bar" -"foo" --- lib/reporters/base.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index b21fefa21f..d8687c7278 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -182,10 +182,13 @@ exports.list = function(failures){ // actual / expected diff if ('string' == typeof actual && 'string' == typeof expected) { fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n'); + var match = message.match(/^([^:]+): expected/); + msg = match ? '\n ' + color('error message', match[1]) : ''; + if (exports.inlineDiffs) { - msg = inlineDiff(err, escape); + msg += inlineDiff(err, escape); } else { - msg = unifiedDiff(err, escape); + msg += unifiedDiff(err, escape); } } @@ -462,3 +465,5 @@ function sameType(a, b) { b = Object.prototype.toString.call(b); return a == b; } + +