Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error.showDiff behavior for multiline strings #711

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ exports.list = function(failures){
, expected = err.expected
, escape = true;

// explicitly show diff
if (err.showDiff) {
// explicitly show diff for non-string values
// no need to call JSON.stringify on strings and escape should be true if
// value is a string, otherwise multi-line diffs won't work properly
if (err.showDiff && ('string' != typeof actual || 'string' != typeof expected)) {
escape = false;
err.actual = actual = JSON.stringify(actual, null, 2);
err.expected = expected = JSON.stringify(expected, null, 2);
Expand Down
10 changes: 8 additions & 2 deletions test/acceptance/diffs.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ describe('diffs', function(){
})

it('should display a word diff for large strings', function(){
// cssin.should.equal(cssout);
var err = new Error();
err.message = 'strings are not the same';
err.expected = cssout;
err.actual = cssin;
// showDiff = true to check conflicts with multi-line string diffs
err.showDiff = true;
// throw err;
})
})
})