@jest/expect-utils 30.0.0-alpha.1 → 30.0.0-alpha.3

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
@@ -4,6 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+
7
8
  export declare const arrayBufferEquality: (
8
9
  a: unknown,
9
10
  b: unknown,
@@ -60,9 +61,9 @@ export declare const iterableEquality: (
60
61
  ) => boolean | undefined;
61
62
 
62
63
  export declare const partition: <T>(
63
- items: T[],
64
+ items: Array<T>,
64
65
  predicate: (arg: T) => boolean,
65
- ) => [T[], T[]];
66
+ ) => [Array<T>, Array<T>];
66
67
 
67
68
  export declare const pathAsArray: (propertyPath: string) => Array<any>;
68
69
 
package/build/index.js CHANGED
@@ -170,8 +170,8 @@ function eq(a, b, aStack, bStack, customTesters, strictCheck) {
170
170
  const testerContext = {
171
171
  equals
172
172
  };
173
- for (let i = 0; i < customTesters.length; i++) {
174
- const customTesterResult = customTesters[i].call(testerContext, a, b, customTesters);
173
+ for (const item of customTesters) {
174
+ const customTesterResult = item.call(testerContext, a, b, customTesters);
175
175
  if (customTesterResult !== undefined) {
176
176
  return customTesterResult;
177
177
  }
@@ -212,6 +212,9 @@ function eq(a, b, aStack, bStack, customTesters, strictCheck) {
212
212
  // RegExps are compared by their source patterns and flags.
213
213
  case '[object RegExp]':
214
214
  return a.source === b.source && a.flags === b.flags;
215
+ // URLs are compared by their href property which contains the entire url string.
216
+ case '[object URL]':
217
+ return a.href === b.href;
215
218
  }
216
219
  if (typeof a !== 'object' || typeof b !== 'object') {
217
220
  return false;
@@ -290,7 +293,7 @@ function keys(obj, hasKey) {
290
293
  keys.push(key);
291
294
  }
292
295
  }
293
- return keys.concat(Object.getOwnPropertySymbols(obj).filter(symbol => Object.getOwnPropertyDescriptor(obj, symbol).enumerable));
296
+ return [...keys, ...Object.getOwnPropertySymbols(obj).filter(symbol => Object.getOwnPropertyDescriptor(obj, symbol).enumerable)];
294
297
  }
295
298
  function hasKey(obj, key) {
296
299
  return Object.prototype.hasOwnProperty.call(obj, key);
@@ -338,10 +341,12 @@ const hasPropertyInObject = (object, key) => {
338
341
  };
339
342
 
340
343
  // Retrieves an object's keys for evaluation by getObjectSubset. This evaluates
341
- // the prototype chain for string keys but not for symbols. (Otherwise, it
342
- // could find values such as a Set or Map's Symbol.toStringTag, with unexpected
343
- // results.)
344
- const getObjectKeys = object => [...Object.keys(object), ...Object.getOwnPropertySymbols(object)];
344
+ // the prototype chain for string keys but not for non-enumerable symbols.
345
+ // (Otherwise, it could find values such as a Set or Map's Symbol.toStringTag,
346
+ // with unexpected results.)
347
+ const getObjectKeys = object => {
348
+ return [...Object.keys(object), ...Object.getOwnPropertySymbols(object).filter(s => Object.getOwnPropertyDescriptor(object, s)?.enumerable)];
349
+ };
345
350
  exports.getObjectKeys = getObjectKeys;
346
351
  const getPath = (object, propertyPath) => {
347
352
  if (!Array.isArray(propertyPath)) {
@@ -506,8 +511,8 @@ aStack = [], bStack = []) => {
506
511
  return false;
507
512
  }
508
513
  if (!(0, _immutableUtils.isImmutableList)(a) && !(0, _immutableUtils.isImmutableOrderedKeyed)(a) && !(0, _immutableUtils.isImmutableOrderedSet)(a) && !(0, _immutableUtils.isImmutableRecord)(a)) {
509
- const aEntries = Object.entries(a);
510
- const bEntries = Object.entries(b);
514
+ const aEntries = entries(a);
515
+ const bEntries = entries(b);
511
516
  if (!(0, _jasmineUtils.equals)(aEntries, bEntries)) {
512
517
  return false;
513
518
  }
@@ -519,8 +524,13 @@ aStack = [], bStack = []) => {
519
524
  return true;
520
525
  };
521
526
  exports.iterableEquality = iterableEquality;
527
+ const entries = obj => {
528
+ if (!isObject(obj)) return [];
529
+ const symbolProperties = Object.getOwnPropertySymbols(obj).filter(key => key !== Symbol.iterator).map(key => [key, obj[key]]);
530
+ return [...symbolProperties, ...Object.entries(obj)];
531
+ };
522
532
  const isObject = a => a !== null && typeof a === 'object';
523
- const isObjectWithKeys = a => isObject(a) && !(a instanceof Error) && !(a instanceof Array) && !(a instanceof Date);
533
+ const isObjectWithKeys = a => isObject(a) && !(a instanceof Error) && !Array.isArray(a) && !(a instanceof Date);
524
534
  const subsetEquality = (object, subset, customTesters = []) => {
525
535
  const filteredCustomTesters = customTesters.filter(t => t !== subsetEquality);
526
536
 
@@ -615,13 +625,13 @@ const pathAsArray = propertyPath => {
615
625
  }
616
626
 
617
627
  // will match everything that's not a dot or a bracket, and "" for consecutive dots.
618
- const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
628
+ const pattern = new RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
619
629
 
620
630
  // Because the regex won't match a dot in the beginning of the path, if present.
621
631
  if (propertyPath[0] === '.') {
622
632
  properties.push('');
623
633
  }
624
- propertyPath.replace(pattern, match => {
634
+ propertyPath.replaceAll(pattern, match => {
625
635
  properties.push(match);
626
636
  return match;
627
637
  });
@@ -644,7 +654,7 @@ exports.isError = isError;
644
654
  function emptyObject(obj) {
645
655
  return obj && typeof obj === 'object' ? Object.keys(obj).length === 0 : false;
646
656
  }
647
- const MULTILINE_REGEXP = /[\r\n]/;
657
+ const MULTILINE_REGEXP = /[\n\r]/;
648
658
  const isOneline = (expected, received) => typeof expected === 'string' && typeof received === 'string' && (!MULTILINE_REGEXP.test(expected) || !MULTILINE_REGEXP.test(received));
649
659
  exports.isOneline = isOneline;
650
660
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jest/expect-utils",
3
- "version": "30.0.0-alpha.1",
3
+ "version": "30.0.0-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/jestjs/jest.git",
@@ -19,13 +19,11 @@
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "dependencies": {
22
- "jest-get-type": "30.0.0-alpha.1"
22
+ "jest-get-type": "30.0.0-alpha.3"
23
23
  },
24
24
  "devDependencies": {
25
- "@tsd/typescript": "^5.0.4",
26
25
  "immutable": "^4.0.0",
27
- "jest-matcher-utils": "30.0.0-alpha.1",
28
- "tsd-lite": "^0.8.0"
26
+ "jest-matcher-utils": "30.0.0-alpha.3"
29
27
  },
30
28
  "engines": {
31
29
  "node": "^16.10.0 || ^18.12.0 || >=20.0.0"
@@ -33,5 +31,5 @@
33
31
  "publishConfig": {
34
32
  "access": "public"
35
33
  },
36
- "gitHead": "d005cb2505c041583e0c5636d006e08666a54b63"
34
+ "gitHead": "e267aff33d105399f2134bad7c8f82285104f3da"
37
35
  }