Skip to content

Commit

Permalink
Merge pull request #1655 from a8m/fix-issue-1241
Browse files Browse the repository at this point in the history
fix(reporter/base): issue #1241
  • Loading branch information
boneskull committed Apr 24, 2015
2 parents ab1a418 + d55221b commit 97a11ac
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
6 changes: 4 additions & 2 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
Expand Down
11 changes: 11 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down
33 changes: 18 additions & 15 deletions test/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 97a11ac

Please sign in to comment.