diff --git a/lib/reporters/base.js b/lib/reporters/base.js index c3ffe6a974..bec43e58f5 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -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/); diff --git a/lib/utils.js b/lib/utils.js index c1393a9c62..3650a707cc 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -455,7 +455,7 @@ function jsonStringify(object, spaces, depth) { default: val = (val == '[Function]' || val == '[Circular]') ? val - : '"' + val + '"'; //string + : JSON.stringify(val); //string } return val; } diff --git a/test/reporters/base.js b/test/reporters/base.js index 3b06f34ad1..b5de60b3f2 100644 --- a/test/reporters/base.js +++ b/test/reporters/base.js @@ -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 () {