Skip to content

Commit d27e36f

Browse files
authored
Update toStrictEqual() to be able to check jest.fn().mock.calls etc. (#13960)
1 parent 5093af4 commit d27e36f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- `[jest-circus]` Update message printed on test timeout ([#13830](https://github.com/facebook/jest/pull/13830))
2424
- `[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))
2525
- `[jest-environment-jsdom]` Stop setting `document` to `null` on teardown ([#13972](https://github.com/facebook/jest/pull/13972))
26+
- `[@jest/expect-utils]` Update `toStrictEqual()` to be able to check `jest.fn().mock.calls` ([#13960](https://github.com/facebook/jest/pull/13960))
2627
- `[@jest/test-result]` Allow `TestResultsProcessor` type to return a Promise ([#13950](https://github.com/facebook/jest/pull/13950))
2728

2829
### Chore & Maintenance

packages/expect-utils/src/__tests__/utils.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
getPath,
1616
iterableEquality,
1717
subsetEquality,
18+
typeEquality,
1819
} from '../utils';
1920

2021
describe('getPath()', () => {
@@ -546,6 +547,12 @@ describe('iterableEquality', () => {
546547
});
547548
});
548549

550+
describe('typeEquality', () => {
551+
test('returns undefined if given mock.calls and []', () => {
552+
expect(typeEquality(jest.fn().mock.calls, [])).toBeUndefined();
553+
});
554+
});
555+
549556
describe('arrayBufferEquality', () => {
550557
test('returns undefined if given a non instance of ArrayBuffer', () => {
551558
expect(arrayBufferEquality(2, 's')).toBeUndefined();

packages/expect-utils/src/utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,16 @@ export const subsetEquality = (
370370

371371
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
372372
export const typeEquality = (a: any, b: any): boolean | undefined => {
373-
if (a == null || b == null || a.constructor === b.constructor) {
373+
if (
374+
a == null ||
375+
b == null ||
376+
a.constructor === b.constructor ||
377+
// Since Jest globals are different from Node globals,
378+
// constructors are different even between arrays when comparing properties of mock objects.
379+
// Both of them should be able to compare correctly when they are array-to-array.
380+
// https://github.com/facebook/jest/issues/2549
381+
(Array.isArray(a) && Array.isArray(b))
382+
) {
374383
return undefined;
375384
}
376385

0 commit comments

Comments
 (0)