@jest/expect-utils
Advanced tools
+0
-2
@@ -94,3 +94,1 @@ /** | ||
| export declare const typeEquality: (a: any, b: any) => boolean | undefined; | ||
| export {}; |
+38
-6
@@ -436,3 +436,7 @@ /*! | ||
| if (a.constructor !== b.constructor) { | ||
| return false; | ||
| // Same cross-realm constructor check as typeEquality — see #14011. | ||
| // https://github.com/jestjs/jest/issues/14011 | ||
| if (a.constructor == null || b.constructor == null || a.constructor.name !== b.constructor.name || !isNativeFunction(a.constructor) || !isNativeFunction(b.constructor)) { | ||
| return false; | ||
| } | ||
| } | ||
@@ -507,8 +511,22 @@ let length = aStack.length; | ||
| } | ||
| const bIterator = b[IteratorSymbol](); | ||
| for (const aValue of a) { | ||
| const nextB = bIterator.next(); | ||
| if (nextB.done || !(0, _jasmineUtils.equals)(aValue, nextB.value, filteredCustomTesters)) { | ||
| let aIterator; | ||
| let bIterator; | ||
| try { | ||
| aIterator = a[IteratorSymbol](); | ||
| bIterator = b[IteratorSymbol](); | ||
| } catch { | ||
| // If the iterator factory itself throws (e.g. a TypedArray method used as | ||
| // [Symbol.iterator] on a plain object), we cannot compare as iterables. | ||
| // Return undefined so equals() falls through to Object.is / property checks. | ||
| aStack.pop(); | ||
| bStack.pop(); | ||
| return undefined; | ||
| } | ||
| let aStep = aIterator.next(); | ||
| while (!aStep.done) { | ||
| const bStep = bIterator.next(); | ||
| if (bStep.done || !(0, _jasmineUtils.equals)(aStep.value, bStep.value, filteredCustomTesters)) { | ||
| return false; | ||
| } | ||
| aStep = aIterator.next(); | ||
| } | ||
@@ -572,4 +590,9 @@ if (!bIterator.next().done) { | ||
| // Returns true if `fn` is a native function (its toString contains "[native code]"). | ||
| exports.subsetEquality = subsetEquality; | ||
| function isNativeFunction(fn) { | ||
| return typeof fn === 'function' && Function.prototype.toString.call(fn).includes('[native code]'); | ||
| } | ||
| // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
| exports.subsetEquality = subsetEquality; | ||
| const typeEquality = (a, b) => { | ||
@@ -584,2 +607,11 @@ if (a == null || b == null || a.constructor === b.constructor || | ||
| } | ||
| // structuredClone (and other cross-realm calls) return objects whose | ||
| // constructors come from a different VM context, so identity checks fail. | ||
| // Fall back to comparing constructor names for native built-ins only — | ||
| // user-defined classes still need identity equality. | ||
| // https://github.com/jestjs/jest/issues/14011 | ||
| if (a.constructor != null && b.constructor != null && a.constructor.name === b.constructor.name && isNativeFunction(a.constructor) && isNativeFunction(b.constructor)) { | ||
| return undefined; | ||
| } | ||
| return false; | ||
@@ -586,0 +618,0 @@ }; |
+3
-3
| { | ||
| "name": "@jest/expect-utils", | ||
| "version": "30.3.0", | ||
| "version": "30.4.0", | ||
| "repository": { | ||
@@ -26,3 +26,3 @@ "type": "git", | ||
| "immutable": "^5.1.2", | ||
| "jest-matcher-utils": "30.3.0" | ||
| "jest-matcher-utils": "30.4.0" | ||
| }, | ||
@@ -35,3 +35,3 @@ "engines": { | ||
| }, | ||
| "gitHead": "efb59c2e81083f8dc941f20d6d20a3af2dc8d068" | ||
| "gitHead": "5cbb21e0b3037edb42e503ec1a1ce80efad40c20" | ||
| } |
32694
4.8%783
3.85%