Skip to content

Commit

Permalink
Add array check
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuibu committed Feb 27, 2023
1 parent bb39cb2 commit ab48a26
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/expect-utils/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit ab48a26

Please sign in to comment.