diff --git a/lib/reporters/base.js b/lib/reporters/base.js index bec43e58f5..fac16f3b24 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.js index 3650a707cc..12c4ea6850 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.js index b5de60b3f2..527697971c 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 () {