Skip to content

Commit

Permalink
Fix deepEqual() skip. Closes #337
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Sep 28, 2019
1 parent 17c85a0 commit 5ac20bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/deepEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,15 @@ internals.isDeepEqualObj = function (instanceType, obj, ref, options, seen) {
return false;
}

let skipped = 0;
for (const key of objKeys) {
if (options.skip &&
options.skip.includes(key)) {

if (ref[key] === undefined) {
++skipped;
}

continue;
}

Expand All @@ -253,6 +258,12 @@ internals.isDeepEqualObj = function (instanceType, obj, ref, options, seen) {
}
}

if (!options.part &&
objKeys.length - skipped !== keys(ref).length) {

return false;
}

// Check symbols

if (options.symbols !== false) { // Defaults to true
Expand Down
3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,9 @@ describe('deepEqual()', () => {
expect(Hoek.deepEqual({ a: 1, b: 2, [sym]: 3 }, { a: 1, b: 2 })).to.be.false();
expect(Hoek.deepEqual({ a: 1, b: 2, [sym]: 3 }, { a: 1, b: 2 }, { skip: [sym] })).to.be.true();
expect(Hoek.deepEqual({ a: 1, b: 2, [sym]: 3, [Symbol('other')]: true }, { a: 1, b: 2 }, { skip: [sym] })).to.be.false();

expect(Hoek.deepEqual({ a: 1, b: 2 }, { a: 1 }, { skip: ['a'] })).to.be.false();
expect(Hoek.deepEqual({ a: 1 }, { a: 1, b: 2 }, { skip: ['a'] })).to.be.false();
});

it('handles circular dependency', () => {
Expand Down

0 comments on commit 5ac20bc

Please sign in to comment.