Skip to content

Commit

Permalink
Merge pull request #1641 from a8m/raw-string-diff-issue-1241
Browse files Browse the repository at this point in the history
fix(reporter/base): string diff - issue #1241
  • Loading branch information
Travis Jeffery committed Apr 7, 2015
2 parents d7d2d88 + 73e4967 commit 093038b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 3 additions & 5 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ exports.list = function(failures){
if (err.showDiff !== false && sameType(actual, expected)
&& expected !== undefined) {

if ('string' !== typeof actual) {
escape = false;
err.actual = actual = utils.stringify(actual);
err.expected = expected = utils.stringify(expected);
}
escape = false;
err.actual = actual = utils.stringify(actual);
err.expected = expected = utils.stringify(expected);

fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ function jsonStringify(object, spaces, depth) {
default:
val = (val == '[Function]' || val == '[Circular]')
? val
: '"' + val + '"'; //string
: JSON.stringify(val); //string
}
return val;
}
Expand Down
14 changes: 8 additions & 6 deletions test/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,24 @@ describe('Base reporter', function () {

});

it('should not stringify strings', function () {
it('should show string diff as raw data', function () {
var err = new Error('test'),
errOut;

err.actual = "a1";
err.expected = "e2";
err.actual = 'foo\nbar';
err.expected = 'foo\nbaz';
err.showDiff = true;
var test = makeTest(err);

Base.list([test]);

errOut = stdout.join('\n');
errOut.should.not.match(/"/);

errOut.should.match(/"foo\\nbar"/);
errOut.should.match(/"foo\\nbaz"/);
errOut.should.match(/test/);
errOut.should.match(/\- actual/);
errOut.should.match(/\+ expected/);
errOut.should.match(/actual/);
errOut.should.match(/expected/);
});

it('should stringify objects', function () {
Expand Down

0 comments on commit 093038b

Please sign in to comment.