Skip to content

Commit

Permalink
Tidies up code after review
Browse files Browse the repository at this point in the history
  • Loading branch information
harrysarson authored and boneskull committed Mar 6, 2018
1 parent 660bccc commit 8df5727
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 5 additions & 8 deletions lib/reporters/base.js
Expand Up @@ -172,17 +172,14 @@ function stringifyDiffObjs (err) {
* The diff will be either inline or unified dependant on the value
* of `Base.inlineDiff`.
*
* @api private
* @param {String} actual
* @param {String} expected
* @param {string} actual
* @param {string} expected
* @return {string} Diff
*/
var generateDiff = exports.generateDiff = function (actual, expected) {
if (exports.inlineDiffs) {
return inlineDiff(actual, expected);
} else {
return unifiedDiff(actual, expected);
}
return exports.inlineDiffs
? inlineDiff(actual, expected)
: unifiedDiff(actual, expected);
};

/**
Expand Down
18 changes: 10 additions & 8 deletions test/reporters/base.spec.js
Expand Up @@ -137,31 +137,33 @@ describe('Base reporter', function () {
});

describe('Diff generation', function () {
var oldInlineDiffs;

beforeEach(function () {
oldInlineDiffs = Base.inlineDiffs;
});

afterEach(function () {
Base.inlineDiffs = oldInlineDiffs;
});

it('should generate unified diffs if `inlineDiff === false`', function () {
var actual = 'a foo unified diff';
var expected = 'a bar unified diff';

var oldInlineDiffs = Base.inlineDiffs;
Base.inlineDiffs = false;

var output = Base.generateDiff(actual, expected);

Base.inlineDiffs = oldInlineDiffs;

expect(output).to.equal('\n + expected - actual\n\n -a foo unified diff\n +a bar unified diff\n ');
});

it('should generate inline diffs if `inlineDiffs === true`', function () {
var actual = 'a foo inline diff';
var expected = 'a bar inline diff';

var oldInlineDiffs = Base.inlineDiffs;
Base.inlineDiffs = true;

var output = Base.generateDiff(actual, expected);

Base.inlineDiffs = oldInlineDiffs;

expect(output).to.equal(' \n actual expected\n \n a foobar inline diff\n ');
});
});
Expand Down

0 comments on commit 8df5727

Please sign in to comment.