Skip to content

Commit

Permalink
Merge pull request #574 from lucasfcosta/showDiff-with-act-and-exp
Browse files Browse the repository at this point in the history
New showDiff behaviour also depending on expected and actual values
  • Loading branch information
keithamus committed Dec 20, 2015
2 parents c772b42 + bca1700 commit 2583873
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/chai/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ module.exports = function (_chai, util) {

Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual, showDiff) {
var ok = util.test(this, arguments);
if (true !== showDiff) showDiff = false;
if (false !== showDiff) showDiff = true;
if (undefined === expected && undefined === _actual) showDiff = false;
if (true !== config.showDiff) showDiff = false;

if (!ok) {
Expand Down
29 changes: 29 additions & 0 deletions test/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,33 @@ describe('assert', function () {
}, 'expected {} to not be frozen');
});
});

it('showDiff true with actual and expected args', function() {
try {
new chai.Assertion().assert(
'one' === 'two'
, 'expected #{this} to equal #{exp}'
, 'expected #{this} to not equal #{act}'
, 'one'
, 'two'
);
} catch(e) {
assert.isTrue(e.showDiff);
}
});

it('showDiff false without expected and actual', function() {
try {
new chai.Assertion().assert(
'one' === 'two'
, 'expected #{this} to equal #{exp}'
, 'expected #{this} to not equal #{act}'
, 'one'
, 'two'
, false
);
} catch(e) {
assert.isFalse(e.showDiff);
}
});
});

0 comments on commit 2583873

Please sign in to comment.