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

New showDiff behaviour also depending on expected and actual values #574

Merged
merged 1 commit into from
Dec 20, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
});
});