From 3f2136629e5fa043985b1e835253c2ae20cf67b2 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki Date: Mon, 6 Apr 2015 22:59:20 +0300 Subject: [PATCH] fix(reporter/base): string diff - issue #1241 Show string diff as a raw data, this fix issue #1241. --- lib/reporters/base.js | 8 +++----- lib/utils.js | 2 +- test/reporters/base.js | 14 ++++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) 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 () {