☕️ Classic, reliable, trusted test framework for Node.js and the browser
fix(reporter/base): issue #1241
Ariel Mashrakid55221bc967f
diff --git a/lib/reporters/base.js b/lib/reporters/base.jsindex bec43e58..fac16f3b 100644--- a/lib/reporters/base.js+++ b/lib/reporters/base.js@@ -190,8 +190,10 @@ exports.list = function(failures){&& expected !== undefined) {escape = false;- err.actual = actual = utils.stringify(actual);- err.expected = expected = utils.stringify(expected);+ if (!(utils.isString(actual) && utils.isString(expected))) {+ 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 3650a707..12c4ea68 100644--- a/lib/utils.js+++ b/lib/utils.js@@ -46,6 +46,17 @@ exports.forEach = function(arr, fn, scope){fn.call(scope, arr[i], i);};+/**+ * Test if the given obj is type of string+ *+ * @param {Object} obj+ * @returns Boolean+ */++exports.isString = function(obj) {+ return 'string' === typeof obj;+};+/*** Array#map (<=IE8)*diff --git a/test/reporters/base.js b/test/reporters/base.jsindex b5de60b3..52769797 100644--- a/test/reporters/base.js+++ b/test/reporters/base.js@@ -88,24 +88,27 @@ describe('Base reporter', function () {});- it('should show string diff as raw data', function () {- var err = new Error('test'),- errOut;-- err.actual = 'foo\nbar';- err.expected = 'foo\nbaz';- err.showDiff = true;- var test = makeTest(err);+ describe('Getting two strings', function() {+ // Fix regression V1.2.1(see: issue #1241)+ it('should show strings diff as is', function () {+ var err = new Error('test'),+ errOut;++ err.actual = 'foo\nbar';+ err.expected = 'foo\nbaz';+ err.showDiff = true;+ var test = makeTest(err);- Base.list([test]);+ Base.list([test]);- errOut = stdout.join('\n');+ errOut = stdout.join('\n');- errOut.should.match(/"foo\\nbar"/);- errOut.should.match(/"foo\\nbaz"/);- errOut.should.match(/test/);- errOut.should.match(/actual/);- errOut.should.match(/expected/);+ errOut.should.not.match(/"foo\\nbar"/);+ errOut.should.match(/foo/).and.match(/bar/);+ errOut.should.match(/test/);+ errOut.should.match(/actual/);+ errOut.should.match(/expected/);+ });});it('should stringify objects', function () {