Skip to content

Commit

Permalink
re-add stringify during list to appease tests, open for discussion if…
Browse files Browse the repository at this point in the history
… this is correct behavior
  • Loading branch information
abrady0 committed Oct 20, 2017
1 parent 09226eb commit 760b4db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,17 @@ exports.cursor = {
}
};

function showDiff(err) {
function showDiff (err) {
return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
}

function stringifyDiffObjs (err) {
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
err.actual = utils.stringify(err.actual);
err.expected = utils.stringify(err.expected);
}
}

/**
* Output the given `failures` as a list.
*
Expand Down Expand Up @@ -204,6 +211,7 @@ exports.list = function (failures) {
}
// explicitly show diff
if (showDiff(err)) {
stringifyDiffObjs(err);
escape = false;
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
Expand Down Expand Up @@ -290,10 +298,7 @@ function Base (runner) {
stats.failures = stats.failures || 0;
stats.failures++;
if (showDiff(err)) {
if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
err.actual = utils.stringify(err.actual);
err.expected = utils.stringify(err.expected);
}
stringifyDiffObjs(err);
}
test.err = err;
failures.push(test);
Expand Down
2 changes: 1 addition & 1 deletion test/reporters/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('List reporter', function () {

Base.cursor = cachedCursor;
});
it('should immediately construct fail strings', function() {
it('should immediately construct fail strings', function () {
var actual = { a: 'actual' };
var expected = { a: 'expected' };
var test = {};
Expand Down

0 comments on commit 760b4db

Please sign in to comment.