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

Update toStrictEqual() to be able to check jest.fn().mock.calls etc. #13960

Merged
merged 7 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions packages/expect-utils/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getPath,
iterableEquality,
subsetEquality,
typeEquality,
} from '../utils';

describe('getPath()', () => {
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 10 additions & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down