☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix(reporter/base): string diff - issue #1241
Ariel Mashraki73e49676cc92
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex c3ffe6a9..bec43e58 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.jsindex c1393a9c..3650a707 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.jsindex 3b06f34a..b5de60b3 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 () {