@jest/expect-utils 30.3.0 → 30.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.d.ts CHANGED
@@ -91,5 +91,3 @@ export declare interface TesterContext {
91
91
  }
92
92
 
93
93
  export declare const typeEquality: (a: any, b: any) => boolean | undefined;
94
-
95
- export {};
package/build/index.js CHANGED
@@ -433,7 +433,11 @@ aStack = [], bStack = []) => {
433
433
  return undefined;
434
434
  }
435
435
  if (a.constructor !== b.constructor) {
436
- return false;
436
+ // Same cross-realm constructor check as typeEquality — see #14011.
437
+ // https://github.com/jestjs/jest/issues/14011
438
+ if (a.constructor == null || b.constructor == null || a.constructor.name !== b.constructor.name || !isNativeFunction(a.constructor) || !isNativeFunction(b.constructor)) {
439
+ return false;
440
+ }
437
441
  }
438
442
  let length = aStack.length;
439
443
  while (length--) {
@@ -503,12 +507,26 @@ aStack = [], bStack = []) => {
503
507
  return allFound;
504
508
  }
505
509
  }
506
- const bIterator = b[IteratorSymbol]();
507
- for (const aValue of a) {
508
- const nextB = bIterator.next();
509
- if (nextB.done || !(0, _jasmineUtils.equals)(aValue, nextB.value, filteredCustomTesters)) {
510
+ let aIterator;
511
+ let bIterator;
512
+ try {
513
+ aIterator = a[IteratorSymbol]();
514
+ bIterator = b[IteratorSymbol]();
515
+ } catch {
516
+ // If the iterator factory itself throws (e.g. a TypedArray method used as
517
+ // [Symbol.iterator] on a plain object), we cannot compare as iterables.
518
+ // Return undefined so equals() falls through to Object.is / property checks.
519
+ aStack.pop();
520
+ bStack.pop();
521
+ return undefined;
522
+ }
523
+ let aStep = aIterator.next();
524
+ while (!aStep.done) {
525
+ const bStep = bIterator.next();
526
+ if (bStep.done || !(0, _jasmineUtils.equals)(aStep.value, bStep.value, filteredCustomTesters)) {
510
527
  return false;
511
528
  }
529
+ aStep = aIterator.next();
512
530
  }
513
531
  if (!bIterator.next().done) {
514
532
  return false;
@@ -567,8 +585,13 @@ const subsetEquality = (object, subset, customTesters = []) => {
567
585
  return subsetEqualityWithContext()(object, subset);
568
586
  };
569
587
 
570
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
588
+ // Returns true if `fn` is a native function (its toString contains "[native code]").
571
589
  exports.subsetEquality = subsetEquality;
590
+ function isNativeFunction(fn) {
591
+ return typeof fn === 'function' && Function.prototype.toString.call(fn).includes('[native code]');
592
+ }
593
+
594
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
572
595
  const typeEquality = (a, b) => {
573
596
  if (a == null || b == null || a.constructor === b.constructor ||
574
597
  // Since Jest globals are different from Node globals,
@@ -578,6 +601,15 @@ const typeEquality = (a, b) => {
578
601
  Array.isArray(a) && Array.isArray(b)) {
579
602
  return undefined;
580
603
  }
604
+
605
+ // structuredClone (and other cross-realm calls) return objects whose
606
+ // constructors come from a different VM context, so identity checks fail.
607
+ // Fall back to comparing constructor names for native built-ins only —
608
+ // user-defined classes still need identity equality.
609
+ // https://github.com/jestjs/jest/issues/14011
610
+ if (a.constructor != null && b.constructor != null && a.constructor.name === b.constructor.name && isNativeFunction(a.constructor) && isNativeFunction(b.constructor)) {
611
+ return undefined;
612
+ }
581
613
  return false;
582
614
  };
583
615
  exports.typeEquality = typeEquality;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jest/expect-utils",
3
- "version": "30.3.0",
3
+ "version": "30.4.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/jestjs/jest.git",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "immutable": "^5.1.2",
26
- "jest-matcher-utils": "30.3.0"
26
+ "jest-matcher-utils": "30.4.1"
27
27
  },
28
28
  "engines": {
29
29
  "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0"
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "efb59c2e81083f8dc941f20d6d20a3af2dc8d068"
34
+ "gitHead": "b3b4a09ed3005369dacc7466d1d2122797283785"
35
35
  }