Skip to content

Commit

Permalink
feat: add a '.toIncludeSamePartialMembers()' custom matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
npwork committed Aug 9, 2024
1 parent cd98f8e commit a884c9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/matchers/toIncludeSamePartialMembers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ describe('.toIncludeSamePartialMembers', () => {
]);
});

test('passes when array values matches the partial members of the set in different order', () => {
expect([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }]).toIncludeSamePartialMembers([
{ foo: 'bar' },
{ hello: 'world' },
]);
});

test('fails when array values do not contain any of the members of the set', () => {
expect(() =>
expect([{ hello: 'world' }, { foo: 'bar', baz: 'qux' }]).toIncludeSamePartialMembers([{ foo: 'qux' }]),
Expand Down
6 changes: 6 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ declare namespace jest {
*/
toIncludeAllPartialMembers<E = unknown>(members: readonly E[]): R;

/**
* Use `.toIncludeSamePartialMembers` when checking if an `Array` contains exactly the same partial members as a given set, in any order
* @param {Array.<*>} members
*/
toIncludeSamePartialMembers<E = unknown>(members: readonly E[]): R;

/**
* Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the members of a given set.
* @param {Array.<*>} members
Expand Down

0 comments on commit a884c9f

Please # to comment.