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

docs: clarify the difference between toIncludeAllMembers and toIncludeSameMembers #647

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions test/matchers/toIncludeSameMembers.test.js
Expand Up @@ -15,6 +15,10 @@ describe('.toIncludeSameMembers', () => {
test('passes when arrays match in a different order', () => {
expect([1, 2, 3]).toIncludeSameMembers([3, 1, 2]);
expect([{ foo: 'bar' }, { baz: 'qux' }]).toIncludeSameMembers([{ baz: 'qux' }, { foo: 'bar' }]);
expect([{ foo: 'bar' }, { baz: 'qux' }, { fred: 'thud' }]).not.toIncludeSameMembers([
{ baz: 'qux' },
{ foo: 'bar' },
]);
});

test('fails when the arrays are not equal in length', () => {
Expand Down
6 changes: 3 additions & 3 deletions types/index.d.ts
Expand Up @@ -63,7 +63,7 @@ interface CustomMatchers<R> extends Record<string, any> {
toBeBefore(date: Date): R;

/**
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the members of a given set.
* @param {Array.<*>} members
*/
toIncludeAllMembers<E = unknown>(members: readonly E[]): R;
Expand Down Expand Up @@ -491,13 +491,13 @@ declare namespace jest {
toBeBefore(date: Date): R;

/**
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
* Use `.toIncludeAllMembers` when checking if an `Array` contains all of the members of a given set.
* @param {Array.<*>} members
*/
toIncludeAllMembers<E = unknown>(members: readonly E[]): R;

/**
* Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of the same partial members of a given set.
* Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of the partial members of a given set.
* @param {Array.<*>} members
*/
toIncludeAllPartialMembers<E = unknown>(members: readonly E[]): R;
Expand Down
8 changes: 5 additions & 3 deletions website/docs/matchers/Array.mdx
Expand Up @@ -28,18 +28,19 @@ Use `.toBeArrayOfSize` when checking if a value is an `Array` of size x.

### .toIncludeAllMembers([members])

Use `.toIncludeAllMembers` when checking if an `Array` contains all of the same members of a given set.
Use `.toIncludeAllMembers` when checking if an `Array` contains all of the members of a given set.

<TestFile name="toIncludeAllMembers">
{`test('passes when given array values match the members of the set', () => {
expect([1, 2, 3]).toIncludeAllMembers([2, 1, 3]);
expect([1, 2, 2]).toIncludeAllMembers([2, 1]);
expect([1, 2, 2]).not.toIncludeAllMembers([3, 1]);
});`}
</TestFile>

### .toIncludeAllPartialMembers([members])

Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of the same partial members of a given set.
Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of the partial members of a given set, in any order.

<TestFile name="toIncludeAllPartialMembers">
{`test('passes when given array values match the partial members of the set', () => {
Expand All @@ -61,12 +62,13 @@ Use `.toIncludeAnyMembers` when checking if an `Array` contains any of the membe

### .toIncludeSameMembers([members])

Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in any order.
Use `.toIncludeSameMembers` when checking if two arrays contain members in exact match, in any order.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is clearer. The matcher is using the equals function, which is why the original was worded the way it was.


<TestFile name="toIncludeSameMembers">
{`test('passes when arrays match in a different order', () => {
expect([1, 2, 3]).toIncludeSameMembers([3, 1, 2]);
expect([{ foo: 'bar' }, { baz: 'qux' }]).toIncludeSameMembers([{ baz: 'qux' }, { foo: 'bar' }]);
expect([1, 2, 2]).not.toIncludeSameMembers([2, 1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change this?

});`}
</TestFile>

Expand Down