diff --git a/CHANGELOG.md b/CHANGELOG.md index a8aa33f482eb..360d7ca1cbe1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,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-environment-jsdom]` Stop setting `document` to `null` on teardown ([#13972](https://github.com/facebook/jest/pull/13972)) +- `[@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)) ### Chore & Maintenance 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(); diff --git a/packages/expect-utils/src/utils.ts b/packages/expect-utils/src/utils.ts index 89f0461b37f0..62c3085a56fa 100644 --- a/packages/expect-utils/src/utils.ts +++ b/packages/expect-utils/src/utils.ts @@ -370,7 +370,16 @@ 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) { + 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 + (Array.isArray(a) && Array.isArray(b)) + ) { return undefined; }