From ab48a26cf42f9d2c35eac52d87f31e1beea83daf Mon Sep 17 00:00:00 2001 From: ibuibu Date: Mon, 27 Feb 2023 22:51:00 +0900 Subject: [PATCH 1/6] Add array check --- packages/expect-utils/src/utils.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 89f0461b37f0..93a203f49edf 100644 --- a/packages/expect-utils/src/utils.ts +++ b/packages/expect-utils/src/utils.ts @@ -370,7 +370,20 @@ export const subsetEquality = ( // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const typeEquality = (a: any, b: any): boolean | undefined => { - if (a == null || b == null || a.constructor === b.constructor) { + // Since Jest globals are different from Node globals, + // constructors are different even between arrays when comparing properties of mock objects. + // Both of them should be able to compare correctly when they are array-to-array. + // https://github.com/facebook/jest/issues/2549 + const areBothArray = + Array.isArray(a) && + Array.isArray(b) && + a.constructor.toString() === b.constructor.toString(); + if ( + a == null || + b == null || + a.constructor === b.constructor || + areBothArray + ) { return undefined; } From e86a63a1c84b6c72cb7ef5e8cf4b8f9b760d1027 Mon Sep 17 00:00:00 2001 From: ibuibu Date: Mon, 27 Feb 2023 23:14:19 +0900 Subject: [PATCH 2/6] Add test --- packages/expect-utils/src/__tests__/utils.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/expect-utils/src/__tests__/utils.test.ts b/packages/expect-utils/src/__tests__/utils.test.ts index baa97a47b973..fd1e2c588ed5 100644 --- a/packages/expect-utils/src/__tests__/utils.test.ts +++ b/packages/expect-utils/src/__tests__/utils.test.ts @@ -15,6 +15,7 @@ import { getPath, iterableEquality, subsetEquality, + typeEquality, } from '../utils'; describe('getPath()', () => { @@ -546,6 +547,12 @@ describe('iterableEquality', () => { }); }); +describe('typeEquality', () => { + test('returns undefined if given mock.calls and []', () => { + expect(typeEquality(jest.fn().mock.calls, [])).toBeUndefined(); + }); +}); + describe('arrayBufferEquality', () => { test('returns undefined if given a non instance of ArrayBuffer', () => { expect(arrayBufferEquality(2, 's')).toBeUndefined(); From 5c483e54db8402069853025b990b6165691b9243 Mon Sep 17 00:00:00 2001 From: ibuibu Date: Tue, 28 Feb 2023 08:27:57 +0900 Subject: [PATCH 3/6] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4f5bbe26c2b..2740c0289595 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[expect-util]` Update toStrictEqual() to be able to check jest.fn().mock.calls etc. ([#13960](https://github.com/facebook/jest/pull/13960)) - `[jest-changed-files]` Support Sapling ([#13941](https://github.com/facebook/jest/pull/13941)) - `[jest-circus, @jest/cli, jest-config]` Add feature to randomize order of tests via CLI flag or through the config file([#12922](https://github.com/facebook/jest/pull/12922)) - `[jest-cli, jest-config, @jest/core, jest-haste-map, @jest/reporters, jest-runner, jest-runtime, @jest/types]` Add `workerThreads` configuration option to allow using [worker threads](https://nodejs.org/dist/latest/docs/api/worker_threads.html) for parallelization ([#13939](https://github.com/facebook/jest/pull/13939)) From 05f6e5107482efa6ef9b0d296f32732e730592de Mon Sep 17 00:00:00 2001 From: ibuibu Date: Wed, 1 Mar 2023 09:00:10 +0900 Subject: [PATCH 4/6] remove unnecessary judge --- packages/expect-utils/src/utils.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 93a203f49edf..62c3085a56fa 100644 --- a/packages/expect-utils/src/utils.ts +++ b/packages/expect-utils/src/utils.ts @@ -370,19 +370,15 @@ export const subsetEquality = ( // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export const typeEquality = (a: any, b: any): boolean | undefined => { - // Since Jest globals are different from Node globals, - // constructors are different even between arrays when comparing properties of mock objects. - // Both of them should be able to compare correctly when they are array-to-array. - // https://github.com/facebook/jest/issues/2549 - const areBothArray = - Array.isArray(a) && - Array.isArray(b) && - a.constructor.toString() === b.constructor.toString(); if ( a == null || b == null || a.constructor === b.constructor || - areBothArray + // Since Jest globals are different from Node globals, + // constructors are different even between arrays when comparing properties of mock objects. + // Both of them should be able to compare correctly when they are array-to-array. + // https://github.com/facebook/jest/issues/2549 + (Array.isArray(a) && Array.isArray(b)) ) { return undefined; } From 385a83a1d42afed3dedece1b91a1a43810a04971 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Mar 2023 07:47:15 +0100 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2740c0289595..5c3a13dee02f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ### Features -- `[expect-util]` Update toStrictEqual() to be able to check jest.fn().mock.calls etc. ([#13960](https://github.com/facebook/jest/pull/13960)) - `[jest-changed-files]` Support Sapling ([#13941](https://github.com/facebook/jest/pull/13941)) - `[jest-circus, @jest/cli, jest-config]` Add feature to randomize order of tests via CLI flag or through the config file([#12922](https://github.com/facebook/jest/pull/12922)) - `[jest-cli, jest-config, @jest/core, jest-haste-map, @jest/reporters, jest-runner, jest-runtime, @jest/types]` Add `workerThreads` configuration option to allow using [worker threads](https://nodejs.org/dist/latest/docs/api/worker_threads.html) for parallelization ([#13939](https://github.com/facebook/jest/pull/13939)) @@ -18,6 +17,7 @@ - `[jest-circus]` Update message printed on test timeout ([#13830](https://github.com/facebook/jest/pull/13830)) - `[jest-circus]` Avoid creating the word "testfalse" when `takesDoneCallback` is `false` in the message printed on test timeout AND updated timeouts test ([#13954](https://github.com/facebook/jest/pull/13954)) - `[@jest/test-result]` Allow `TestResultsProcessor` type to return a Promise ([#13950](https://github.com/facebook/jest/pull/13950)) +- `[expect-util]` Update `toStrictEqual()` to be able to check `jest.fn().mock.calls` ([#13960](https://github.com/facebook/jest/pull/13960)) ### Chore & Maintenance From 47800ea12ea1625cd7d2c5874bb5d63ccad215f1 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 6 Mar 2023 07:48:14 +0100 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c3a13dee02f..e0a098018d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,8 @@ - `[jest-circus]` Send test case results for `todo` tests ([#13915](https://github.com/facebook/jest/pull/13915)) - `[jest-circus]` Update message printed on test timeout ([#13830](https://github.com/facebook/jest/pull/13830)) - `[jest-circus]` Avoid creating the word "testfalse" when `takesDoneCallback` is `false` in the message printed on test timeout AND updated timeouts test ([#13954](https://github.com/facebook/jest/pull/13954)) +- `[@jest/expect-utils]` Update `toStrictEqual()` to be able to check `jest.fn().mock.calls` ([#13960](https://github.com/facebook/jest/pull/13960)) - `[@jest/test-result]` Allow `TestResultsProcessor` type to return a Promise ([#13950](https://github.com/facebook/jest/pull/13950)) -- `[expect-util]` Update `toStrictEqual()` to be able to check `jest.fn().mock.calls` ([#13960](https://github.com/facebook/jest/pull/13960)) ### Chore & Maintenance