Skip to content

Commit

Permalink
Include assertion message as context (close #993)
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
blalor authored and travisjeffery committed Oct 12, 2013
1 parent 805c95d commit 34116d5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -462,3 +465,5 @@ function sameType(a, b) {
b = Object.prototype.toString.call(b);
return a == b;
}


0 comments on commit 34116d5

Please sign in to comment.