From 8144905cf707dce863b6868c9f46353428a97dfc Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Wed, 6 Sep 2023 04:59:27 +0900 Subject: [PATCH 1/3] docs: clarify difference between toIncludeAllMembers and toIncludeSameMembers --- website/docs/matchers/Array.mdx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/docs/matchers/Array.mdx b/website/docs/matchers/Array.mdx index 7903a5e6..4745a622 100644 --- a/website/docs/matchers/Array.mdx +++ b/website/docs/matchers/Array.mdx @@ -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. {`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]); });`} ### .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. {`test('passes when given array values match the partial members of the set', () => { @@ -67,6 +68,7 @@ Use `.toIncludeSameMembers` when checking if two arrays contain equal values, in {`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' }]); });`} From 1b9bfaf8168e438f2f8e24d72ef2e2381443d99e Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Wed, 6 Sep 2023 04:59:41 +0900 Subject: [PATCH 2/3] chore: update docs and add test --- test/matchers/toIncludeSameMembers.test.js | 4 ++++ types/index.d.ts | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/matchers/toIncludeSameMembers.test.js b/test/matchers/toIncludeSameMembers.test.js index 020ab2ac..1103cce7 100644 --- a/test/matchers/toIncludeSameMembers.test.js +++ b/test/matchers/toIncludeSameMembers.test.js @@ -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', () => { diff --git a/types/index.d.ts b/types/index.d.ts index a0cef966..909576c5 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -63,7 +63,7 @@ interface CustomMatchers extends Record { 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(members: readonly E[]): R; @@ -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(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(members: readonly E[]): R; From 9467c0b5276bb41531f06695c34d7320920ef6dc Mon Sep 17 00:00:00 2001 From: devjiwonchoi Date: Wed, 11 Oct 2023 20:40:54 +0900 Subject: [PATCH 3/3] docs: update toIncludeSameMembers Co-authored-by: Keegan Witt --- website/docs/matchers/Array.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/matchers/Array.mdx b/website/docs/matchers/Array.mdx index 4745a622..4c442779 100644 --- a/website/docs/matchers/Array.mdx +++ b/website/docs/matchers/Array.mdx @@ -40,7 +40,7 @@ Use `.toIncludeAllMembers` when checking if an `Array` contains all of the membe ### .toIncludeAllPartialMembers([members]) -Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of the 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. {`test('passes when given array values match the partial members of the set', () => { @@ -62,13 +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. {`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' }]); + expect([1, 2, 2]).not.toIncludeSameMembers([2, 1]); });`}