Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reporter/base): issue #1241 #1655

Merged
merged 1 commit into from
Apr 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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