Skip to content

Commit

Permalink
fix(reporter/base): string diff - issue mochajs#1241
Browse files Browse the repository at this point in the history
Show string diff as a raw data, this fix issue mochajs#1241.
  • Loading branch information
a8m authored and amsul committed Apr 18, 2015
1 parent 0feb772 commit 2491ea0
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 2491ea0

Please sign in to comment.