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

Adds guard for empty properties in deepEqual when a matcher is provided #1901

Merged
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
5 changes: 3 additions & 2 deletions lib/sinon/util/core/deep-equal.js
Expand Up @@ -38,11 +38,12 @@ var deepEqual = module.exports = function deepEqual(a, b, matcher) {
}

if (matcher) {
var allKeysMatch = every(Object.keys(a), function (key) {
var keys = Object.keys(a);
var allKeysMatch = every(keys, function (key) {
return matcher(a[key], b[key]);
});

return allKeysMatch;
return keys.length > 0 && allKeysMatch;
}

return false;
Expand Down
13 changes: 13 additions & 0 deletions test/issues/issues-test.js
Expand Up @@ -520,4 +520,17 @@ describe("issues", function () {
stub.restore();
});
});

describe("#1900 - calledWith returns false positive", function () {
it("should return false when call args don't match", function () {
var spy = sinon.spy();
var dateOne = new Date("2018-07-01");
var dateTwo = new Date("2018-07-31");

spy(dateOne);

var calledWith = spy.calledWith(dateTwo);
assert.same(calledWith, false);
});
});
});