Skip to content

Commit

Permalink
fix(toIncludeAllPartialMembers): includes all member entries (jest-co…
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-at authored Nov 29, 2021
1 parent 4c4074c commit a041abf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/matchers/toContainAllEntries/predicate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { equals } from '../../utils';
import toContainEntries from '../toContainEntries/predicate';

export default (obj, entries) => {
if (!obj.hasOwnProperty || entries.length != Object.keys(obj).length) {
return false;
}

return entries.every(([key, value]) => Object.prototype.hasOwnProperty.call(obj, key) && equals(obj[key], value));
return toContainEntries(obj, entries);
};
5 changes: 2 additions & 3 deletions src/matchers/toContainEntries/predicate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { equals } from '../../utils';
import toContainEntry from '../toContainEntry/predicate';

export default (obj, entries) =>
entries.every(([key, value]) => Object.prototype.hasOwnProperty.call(obj, key) && equals(obj[key], value));
export default (obj, entries) => entries.every(entry => toContainEntry(obj, entry));
4 changes: 2 additions & 2 deletions src/matchers/toIncludeAllPartialMembers/predicate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import toContainAnyEntries from '../toContainAnyEntries/predicate';
import toContainEntries from '../toContainEntries/predicate';

export default (array, set) =>
Array.isArray(array) &&
Array.isArray(set) &&
set.every(partial => array.some(value => toContainAnyEntries(value, Object.entries(partial))));
set.every(partial => array.some(value => toContainEntries(value, Object.entries(partial))));
8 changes: 7 additions & 1 deletion src/matchers/toIncludeAllPartialMembers/predicate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ describe('toIncludeAllPartialMembers Predicate', () => {
});

describe('returns false', () => {
test('when Array contains does not contain all of the same nested partial members of given item', () => {
expect(predicate([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }], [{ foo: 'bar', bax: 'qux' }])).toBe(false);
});

test('when Array contains does not contain all of the same nested partial members of given set', () => {
expect(predicate([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }], [{ foo: 'qux' }])).toBe(false);
expect(predicate([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }], [{ hello: 'world' }, { foo: 'qux' }])).toBe(
false,
);
});
});
});

0 comments on commit a041abf

Please sign in to comment.