@jest/expect-utils 29.1.2 → 29.2.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.
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ });
6
+ exports.isImmutableList = isImmutableList;
7
+ exports.isImmutableOrderedKeyed = isImmutableOrderedKeyed;
8
+ exports.isImmutableOrderedSet = isImmutableOrderedSet;
9
+ exports.isImmutableRecord = isImmutableRecord;
10
+ exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
11
+ exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
12
+ /**
13
+ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+
20
+ // SENTINEL constants are from https://github.com/immutable-js/immutable-js/tree/main/src/predicates
21
+ const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
22
+ const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
23
+ const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
24
+ const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
25
+ const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
26
+ function isObjectLiteral(source) {
27
+ return source != null && typeof source === 'object' && !Array.isArray(source);
28
+ }
29
+ function isImmutableUnorderedKeyed(source) {
30
+ return Boolean(
31
+ source &&
32
+ isObjectLiteral(source) &&
33
+ source[IS_KEYED_SENTINEL] &&
34
+ !source[IS_ORDERED_SENTINEL]
35
+ );
36
+ }
37
+ function isImmutableUnorderedSet(source) {
38
+ return Boolean(
39
+ source &&
40
+ isObjectLiteral(source) &&
41
+ source[IS_SET_SENTINEL] &&
42
+ !source[IS_ORDERED_SENTINEL]
43
+ );
44
+ }
45
+ function isImmutableList(source) {
46
+ return Boolean(source && isObjectLiteral(source) && source[IS_LIST_SENTINEL]);
47
+ }
48
+ function isImmutableOrderedKeyed(source) {
49
+ return Boolean(
50
+ source &&
51
+ isObjectLiteral(source) &&
52
+ source[IS_KEYED_SENTINEL] &&
53
+ source[IS_ORDERED_SENTINEL]
54
+ );
55
+ }
56
+ function isImmutableOrderedSet(source) {
57
+ return Boolean(
58
+ source &&
59
+ isObjectLiteral(source) &&
60
+ source[IS_SET_SENTINEL] &&
61
+ source[IS_ORDERED_SENTINEL]
62
+ );
63
+ }
64
+ function isImmutableRecord(source) {
65
+ return Boolean(source && isObjectLiteral(source) && source[IS_RECORD_SYMBOL]);
66
+ }
package/build/index.d.ts CHANGED
@@ -46,7 +46,7 @@ export declare const getPath: (
46
46
  propertyPath: string | Array<string>,
47
47
  ) => GetPath;
48
48
 
49
- export declare function isA(typeName: string, value: unknown): boolean;
49
+ export declare function isA<T>(typeName: string, value: unknown): value is T;
50
50
 
51
51
  export declare const isError: (value: unknown) => value is Error;
52
52
 
package/build/index.js CHANGED
@@ -19,11 +19,8 @@ Object.defineProperty(exports, 'isA', {
19
19
  return _jasmineUtils.isA;
20
20
  }
21
21
  });
22
-
23
22
  var _jasmineUtils = require('./jasmineUtils');
24
-
25
23
  var _utils = require('./utils');
26
-
27
24
  Object.keys(_utils).forEach(function (key) {
28
25
  if (key === 'default' || key === '__esModule') return;
29
26
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -5,13 +5,6 @@ Object.defineProperty(exports, '__esModule', {
5
5
  });
6
6
  exports.equals = void 0;
7
7
  exports.isA = isA;
8
- exports.isImmutableList = isImmutableList;
9
- exports.isImmutableOrderedKeyed = isImmutableOrderedKeyed;
10
- exports.isImmutableOrderedSet = isImmutableOrderedSet;
11
- exports.isImmutableRecord = isImmutableRecord;
12
- exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
13
- exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
14
-
15
8
  /*
16
9
  Copyright (c) 2008-2016 Pivotal Labs
17
10
 
@@ -36,71 +29,57 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36
29
 
37
30
  */
38
31
 
39
- /* eslint-disable */
40
32
  // Extracted out of jasmine 2.5.2
41
33
  const equals = (a, b, customTesters, strictCheck) => {
42
34
  customTesters = customTesters || [];
43
35
  return eq(a, b, [], [], customTesters, strictCheck);
44
36
  };
45
-
46
37
  exports.equals = equals;
47
-
48
38
  function isAsymmetric(obj) {
49
39
  return !!obj && isA('Function', obj.asymmetricMatch);
50
40
  }
51
-
52
41
  function asymmetricMatch(a, b) {
53
- var asymmetricA = isAsymmetric(a),
54
- asymmetricB = isAsymmetric(b);
55
-
42
+ const asymmetricA = isAsymmetric(a);
43
+ const asymmetricB = isAsymmetric(b);
56
44
  if (asymmetricA && asymmetricB) {
57
45
  return undefined;
58
46
  }
59
-
60
47
  if (asymmetricA) {
61
48
  return a.asymmetricMatch(b);
62
49
  }
63
-
64
50
  if (asymmetricB) {
65
51
  return b.asymmetricMatch(a);
66
52
  }
67
- } // Equality function lovingly adapted from isEqual in
68
- // [Underscore](http://underscorejs.org)
53
+ }
69
54
 
55
+ // Equality function lovingly adapted from isEqual in
56
+ // [Underscore](http://underscorejs.org)
70
57
  function eq(a, b, aStack, bStack, customTesters, strictCheck) {
71
- var result = true;
72
- var asymmetricResult = asymmetricMatch(a, b);
73
-
58
+ let result = true;
59
+ const asymmetricResult = asymmetricMatch(a, b);
74
60
  if (asymmetricResult !== undefined) {
75
61
  return asymmetricResult;
76
62
  }
77
-
78
- for (var i = 0; i < customTesters.length; i++) {
79
- var customTesterResult = customTesters[i](a, b);
80
-
63
+ for (let i = 0; i < customTesters.length; i++) {
64
+ const customTesterResult = customTesters[i](a, b);
81
65
  if (customTesterResult !== undefined) {
82
66
  return customTesterResult;
83
67
  }
84
68
  }
85
-
86
69
  if (a instanceof Error && b instanceof Error) {
87
70
  return a.message == b.message;
88
71
  }
89
-
90
72
  if (Object.is(a, b)) {
91
73
  return true;
92
- } // A strict comparison is necessary because `null == undefined`.
93
-
74
+ }
75
+ // A strict comparison is necessary because `null == undefined`.
94
76
  if (a === null || b === null) {
95
77
  return a === b;
96
78
  }
97
-
98
- var className = Object.prototype.toString.call(a);
99
-
79
+ const className = Object.prototype.toString.call(a);
100
80
  if (className != Object.prototype.toString.call(b)) {
101
81
  return false;
102
82
  }
103
-
104
83
  switch (className) {
105
84
  case '[object Boolean]':
106
85
  case '[object String]':
@@ -115,28 +94,26 @@ function eq(a, b, aStack, bStack, customTesters, strictCheck) {
115
94
  // both are `new Primitive()`s
116
95
  return Object.is(a.valueOf(), b.valueOf());
117
96
  }
118
-
119
97
  case '[object Date]':
120
98
  // Coerce dates to numeric primitive values. Dates are compared by their
121
99
  // millisecond representations. Note that invalid dates with millisecond representations
122
100
  // of `NaN` are not equivalent.
123
101
  return +a == +b;
124
102
  // RegExps are compared by their source patterns and flags.
125
-
126
103
  case '[object RegExp]':
127
104
  return a.source === b.source && a.flags === b.flags;
128
105
  }
129
-
130
106
  if (typeof a !== 'object' || typeof b !== 'object') {
131
107
  return false;
132
- } // Use DOM3 method isEqualNode (IE>=9)
108
+ }
133
109
 
110
+ // Use DOM3 method isEqualNode (IE>=9)
134
111
  if (isDomNode(a) && isDomNode(b)) {
135
112
  return a.isEqualNode(b);
136
- } // Used to detect circular references.
137
-
138
- var length = aStack.length;
113
+ }
139
114
 
115
+ // Used to detect circular references.
116
+ let length = aStack.length;
140
117
  while (length--) {
141
118
  // Linear search. Performance is inversely proportional to the number of
142
119
  // unique nested structures.
@@ -147,47 +124,45 @@ function eq(a, b, aStack, bStack, customTesters, strictCheck) {
147
124
  } else if (bStack[length] === b) {
148
125
  return false;
149
126
  }
150
- } // Add the first object to the stack of traversed objects.
151
-
127
+ }
128
+ // Add the first object to the stack of traversed objects.
152
129
  aStack.push(a);
153
- bStack.push(b); // Recursively compare objects and arrays.
130
+ bStack.push(b);
131
+ // Recursively compare objects and arrays.
154
132
  // Compare array lengths to determine if a deep comparison is necessary.
155
-
156
133
  if (strictCheck && className == '[object Array]' && a.length !== b.length) {
157
134
  return false;
158
- } // Deep compare objects.
159
-
160
- var aKeys = keys(a, hasKey),
161
- key;
162
- var bKeys = keys(b, hasKey); // Add keys corresponding to asymmetric matchers if they miss in non strict check mode
135
+ }
163
136
 
137
+ // Deep compare objects.
138
+ const aKeys = keys(a, hasKey);
139
+ let key;
140
+ const bKeys = keys(b, hasKey);
141
+ // Add keys corresponding to asymmetric matchers if they miss in non strict check mode
164
142
  if (!strictCheck) {
165
- for (var index = 0; index !== bKeys.length; ++index) {
143
+ for (let index = 0; index !== bKeys.length; ++index) {
166
144
  key = bKeys[index];
167
-
168
145
  if ((isAsymmetric(b[key]) || b[key] === undefined) && !hasKey(a, key)) {
169
146
  aKeys.push(key);
170
147
  }
171
148
  }
172
-
173
- for (var index = 0; index !== aKeys.length; ++index) {
149
+ for (let index = 0; index !== aKeys.length; ++index) {
174
150
  key = aKeys[index];
175
-
176
151
  if ((isAsymmetric(a[key]) || a[key] === undefined) && !hasKey(b, key)) {
177
152
  bKeys.push(key);
178
153
  }
179
154
  }
180
- } // Ensure that both objects contain the same number of properties before comparing deep equality.
181
-
182
- var size = aKeys.length;
155
+ }
183
156
 
157
+ // Ensure that both objects contain the same number of properties before comparing deep equality.
158
+ let size = aKeys.length;
184
159
  if (bKeys.length !== size) {
185
160
  return false;
186
161
  }
187
-
188
162
  while (size--) {
189
- key = aKeys[size]; // Deep compare each member
163
+ key = aKeys[size];
190
164
 
165
+ // Deep compare each member
191
166
  if (strictCheck)
192
167
  result =
193
168
  hasKey(b, key) &&
@@ -196,41 +171,34 @@ function eq(a, b, aStack, bStack, customTesters, strictCheck) {
196
171
  result =
197
172
  (hasKey(b, key) || isAsymmetric(a[key]) || a[key] === undefined) &&
198
173
  eq(a[key], b[key], aStack, bStack, customTesters, strictCheck);
199
-
200
174
  if (!result) {
201
175
  return false;
202
176
  }
203
- } // Remove the first object from the stack of traversed objects.
204
-
177
+ }
178
+ // Remove the first object from the stack of traversed objects.
205
179
  aStack.pop();
206
180
  bStack.pop();
207
181
  return result;
208
182
  }
209
-
210
183
  function keys(obj, hasKey) {
211
- var keys = [];
212
-
213
- for (var key in obj) {
184
+ const keys = [];
185
+ for (const key in obj) {
214
186
  if (hasKey(obj, key)) {
215
187
  keys.push(key);
216
188
  }
217
189
  }
218
-
219
190
  return keys.concat(
220
191
  Object.getOwnPropertySymbols(obj).filter(
221
192
  symbol => Object.getOwnPropertyDescriptor(obj, symbol).enumerable
222
193
  )
223
194
  );
224
195
  }
225
-
226
196
  function hasKey(obj, key) {
227
197
  return Object.prototype.hasOwnProperty.call(obj, key);
228
198
  }
229
-
230
199
  function isA(typeName, value) {
231
- return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
200
+ return Object.prototype.toString.apply(value) === `[object ${typeName}]`;
232
201
  }
233
-
234
202
  function isDomNode(obj) {
235
203
  return (
236
204
  obj !== null &&
@@ -239,50 +207,4 @@ function isDomNode(obj) {
239
207
  typeof obj.nodeName === 'string' &&
240
208
  typeof obj.isEqualNode === 'function'
241
209
  );
242
- } // SENTINEL constants are from https://github.com/immutable-js/immutable-js/tree/main/src/predicates
243
-
244
- const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
245
- const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
246
- const IS_LIST_SENTINEL = '@@__IMMUTABLE_LIST__@@';
247
- const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
248
- const IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
249
-
250
- function isImmutableUnorderedKeyed(maybeKeyed) {
251
- return !!(
252
- maybeKeyed &&
253
- maybeKeyed[IS_KEYED_SENTINEL] &&
254
- !maybeKeyed[IS_ORDERED_SENTINEL]
255
- );
256
- }
257
-
258
- function isImmutableUnorderedSet(maybeSet) {
259
- return !!(
260
- maybeSet &&
261
- maybeSet[IS_SET_SENTINEL] &&
262
- !maybeSet[IS_ORDERED_SENTINEL]
263
- );
264
- }
265
-
266
- function isImmutableList(maybeList) {
267
- return !!(maybeList && maybeList[IS_LIST_SENTINEL]);
268
- }
269
-
270
- function isImmutableOrderedKeyed(maybeKeyed) {
271
- return !!(
272
- maybeKeyed &&
273
- maybeKeyed[IS_KEYED_SENTINEL] &&
274
- maybeKeyed[IS_ORDERED_SENTINEL]
275
- );
276
- }
277
-
278
- function isImmutableOrderedSet(maybeSet) {
279
- return !!(
280
- maybeSet &&
281
- maybeSet[IS_SET_SENTINEL] &&
282
- maybeSet[IS_ORDERED_SENTINEL]
283
- );
284
- }
285
-
286
- function isImmutableRecord(maybeSet) {
287
- return !!(maybeSet && maybeSet[IS_RECORD_SYMBOL]);
288
210
  }
package/build/utils.js CHANGED
@@ -16,40 +16,32 @@ exports.typeEquality =
16
16
  exports.getPath =
17
17
  exports.getObjectSubset =
18
18
  void 0;
19
-
20
19
  var _jestGetType = require('jest-get-type');
21
-
20
+ var _immutableUtils = require('./immutableUtils');
22
21
  var _jasmineUtils = require('./jasmineUtils');
23
-
24
22
  var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol;
25
-
26
23
  /**
27
24
  * Checks if `hasOwnProperty(object, key)` up the prototype chain, stopping at `Object.prototype`.
28
25
  */
29
26
  const hasPropertyInObject = (object, key) => {
30
27
  const shouldTerminate =
31
28
  !object || typeof object !== 'object' || object === Object.prototype;
32
-
33
29
  if (shouldTerminate) {
34
30
  return false;
35
31
  }
36
-
37
32
  return (
38
33
  Object.prototype.hasOwnProperty.call(object, key) ||
39
34
  hasPropertyInObject(Object.getPrototypeOf(object), key)
40
35
  );
41
36
  };
42
-
43
37
  const getPath = (object, propertyPath) => {
44
38
  if (!Array.isArray(propertyPath)) {
45
39
  propertyPath = pathAsArray(propertyPath);
46
40
  }
47
-
48
41
  if (propertyPath.length) {
49
42
  const lastProp = propertyPath.length === 1;
50
43
  const prop = propertyPath[0];
51
44
  const newObject = object[prop];
52
-
53
45
  if (!lastProp && (newObject === null || newObject === undefined)) {
54
46
  // This is not the last prop in the chain. If we keep recursing it will
55
47
  // hit a `can't access property X of undefined | null`. At this point we
@@ -60,15 +52,11 @@ const getPath = (object, propertyPath) => {
60
52
  traversedPath: []
61
53
  };
62
54
  }
63
-
64
55
  const result = getPath(newObject, propertyPath.slice(1));
65
-
66
56
  if (result.lastTraversedObject === null) {
67
57
  result.lastTraversedObject = object;
68
58
  }
69
-
70
59
  result.traversedPath.unshift(prop);
71
-
72
60
  if (lastProp) {
73
61
  // Does object have the property with an undefined value?
74
62
  // Although primitive values support bracket notation (above)
@@ -76,27 +64,23 @@ const getPath = (object, propertyPath) => {
76
64
  result.endPropIsDefined =
77
65
  !(0, _jestGetType.isPrimitive)(object) && prop in object;
78
66
  result.hasEndProp = newObject !== undefined || result.endPropIsDefined;
79
-
80
67
  if (!result.hasEndProp) {
81
68
  result.traversedPath.shift();
82
69
  }
83
70
  }
84
-
85
71
  return result;
86
72
  }
87
-
88
73
  return {
89
74
  lastTraversedObject: null,
90
75
  traversedPath: [],
91
76
  value: object
92
77
  };
93
- }; // Strip properties from object that are not present in the subset. Useful for
94
- // printing the diff for toMatchObject() without adding unrelated noise.
78
+ };
95
79
 
80
+ // Strip properties from object that are not present in the subset. Useful for
81
+ // printing the diff for toMatchObject() without adding unrelated noise.
96
82
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
97
-
98
83
  exports.getPath = getPath;
99
-
100
84
  const getObjectSubset = (object, subset, seenReferences = new WeakMap()) => {
101
85
  /* eslint-enable @typescript-eslint/explicit-module-boundary-types */
102
86
  if (Array.isArray(object)) {
@@ -116,7 +100,6 @@ const getObjectSubset = (object, subset, seenReferences = new WeakMap()) => {
116
100
  // Avoid unnecessary copy which might return Object instead of subclass.
117
101
  return subset;
118
102
  }
119
-
120
103
  const trimmed = {};
121
104
  seenReferences.set(object, trimmed);
122
105
  Object.keys(object)
@@ -126,25 +109,20 @@ const getObjectSubset = (object, subset, seenReferences = new WeakMap()) => {
126
109
  ? seenReferences.get(object[key])
127
110
  : getObjectSubset(object[key], subset[key], seenReferences);
128
111
  });
129
-
130
112
  if (Object.keys(trimmed).length > 0) {
131
113
  return trimmed;
132
114
  }
133
115
  }
134
-
135
116
  return object;
136
117
  };
137
-
138
118
  exports.getObjectSubset = getObjectSubset;
139
119
  const IteratorSymbol = Symbol.iterator;
140
-
141
120
  const hasIterator = object => !!(object != null && object[IteratorSymbol]);
142
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
143
121
 
122
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
144
123
  const iterableEquality = (
145
124
  a,
146
- b,
147
- /* eslint-enable @typescript-eslint/explicit-module-boundary-types */
125
+ b /* eslint-enable @typescript-eslint/explicit-module-boundary-types */,
148
126
  aStack = [],
149
127
  bStack = []
150
128
  ) => {
@@ -158,13 +136,10 @@ const iterableEquality = (
158
136
  ) {
159
137
  return undefined;
160
138
  }
161
-
162
139
  if (a.constructor !== b.constructor) {
163
140
  return false;
164
141
  }
165
-
166
142
  let length = aStack.length;
167
-
168
143
  while (length--) {
169
144
  // Linear search. Performance is inversely proportional to the number of
170
145
  // unique nested structures.
@@ -174,52 +149,44 @@ const iterableEquality = (
174
149
  return bStack[length] === b;
175
150
  }
176
151
  }
177
-
178
152
  aStack.push(a);
179
153
  bStack.push(b);
180
-
181
154
  const iterableEqualityWithStack = (a, b) =>
182
155
  iterableEquality(a, b, [...aStack], [...bStack]);
183
-
184
156
  if (a.size !== undefined) {
185
157
  if (a.size !== b.size) {
186
158
  return false;
187
159
  } else if (
188
160
  (0, _jasmineUtils.isA)('Set', a) ||
189
- (0, _jasmineUtils.isImmutableUnorderedSet)(a)
161
+ (0, _immutableUtils.isImmutableUnorderedSet)(a)
190
162
  ) {
191
163
  let allFound = true;
192
-
193
164
  for (const aValue of a) {
194
165
  if (!b.has(aValue)) {
195
166
  let has = false;
196
-
197
167
  for (const bValue of b) {
198
168
  const isEqual = (0, _jasmineUtils.equals)(aValue, bValue, [
199
169
  iterableEqualityWithStack
200
170
  ]);
201
-
202
171
  if (isEqual === true) {
203
172
  has = true;
204
173
  }
205
174
  }
206
-
207
175
  if (has === false) {
208
176
  allFound = false;
209
177
  break;
210
178
  }
211
179
  }
212
- } // Remove the first value from the stack of traversed values.
213
-
180
+ }
181
+ // Remove the first value from the stack of traversed values.
214
182
  aStack.pop();
215
183
  bStack.pop();
216
184
  return allFound;
217
185
  } else if (
218
186
  (0, _jasmineUtils.isA)('Map', a) ||
219
- (0, _jasmineUtils.isImmutableUnorderedKeyed)(a)
187
+ (0, _immutableUtils.isImmutableUnorderedKeyed)(a)
220
188
  ) {
221
189
  let allFound = true;
222
-
223
190
  for (const aEntry of a) {
224
191
  if (
225
192
  !b.has(aEntry[0]) ||
@@ -228,42 +195,35 @@ const iterableEquality = (
228
195
  ])
229
196
  ) {
230
197
  let has = false;
231
-
232
198
  for (const bEntry of b) {
233
199
  const matchedKey = (0, _jasmineUtils.equals)(aEntry[0], bEntry[0], [
234
200
  iterableEqualityWithStack
235
201
  ]);
236
202
  let matchedValue = false;
237
-
238
203
  if (matchedKey === true) {
239
204
  matchedValue = (0, _jasmineUtils.equals)(aEntry[1], bEntry[1], [
240
205
  iterableEqualityWithStack
241
206
  ]);
242
207
  }
243
-
244
208
  if (matchedValue === true) {
245
209
  has = true;
246
210
  }
247
211
  }
248
-
249
212
  if (has === false) {
250
213
  allFound = false;
251
214
  break;
252
215
  }
253
216
  }
254
- } // Remove the first value from the stack of traversed values.
255
-
217
+ }
218
+ // Remove the first value from the stack of traversed values.
256
219
  aStack.pop();
257
220
  bStack.pop();
258
221
  return allFound;
259
222
  }
260
223
  }
261
-
262
224
  const bIterator = b[IteratorSymbol]();
263
-
264
225
  for (const aValue of a) {
265
226
  const nextB = bIterator.next();
266
-
267
227
  if (
268
228
  nextB.done ||
269
229
  !(0, _jasmineUtils.equals)(aValue, nextB.value, [
@@ -273,40 +233,34 @@ const iterableEquality = (
273
233
  return false;
274
234
  }
275
235
  }
276
-
277
236
  if (!bIterator.next().done) {
278
237
  return false;
279
238
  }
280
-
281
239
  if (
282
- !(0, _jasmineUtils.isImmutableList)(a) &&
283
- !(0, _jasmineUtils.isImmutableOrderedKeyed)(a) &&
284
- !(0, _jasmineUtils.isImmutableOrderedSet)(a) &&
285
- !(0, _jasmineUtils.isImmutableRecord)(a)
240
+ !(0, _immutableUtils.isImmutableList)(a) &&
241
+ !(0, _immutableUtils.isImmutableOrderedKeyed)(a) &&
242
+ !(0, _immutableUtils.isImmutableOrderedSet)(a) &&
243
+ !(0, _immutableUtils.isImmutableRecord)(a)
286
244
  ) {
287
245
  const aEntries = Object.entries(a);
288
246
  const bEntries = Object.entries(b);
289
-
290
247
  if (!(0, _jasmineUtils.equals)(aEntries, bEntries)) {
291
248
  return false;
292
249
  }
293
- } // Remove the first value from the stack of traversed values.
250
+ }
294
251
 
252
+ // Remove the first value from the stack of traversed values.
295
253
  aStack.pop();
296
254
  bStack.pop();
297
255
  return true;
298
256
  };
299
-
300
257
  exports.iterableEquality = iterableEquality;
301
-
302
258
  const isObject = a => a !== null && typeof a === 'object';
303
-
304
259
  const isObjectWithKeys = a =>
305
260
  isObject(a) &&
306
261
  !(a instanceof Error) &&
307
262
  !(a instanceof Array) &&
308
263
  !(a instanceof Date);
309
-
310
264
  const subsetEquality = (object, subset) => {
311
265
  // subsetEquality needs to keep track of the references
312
266
  // it has already visited to avoid infinite loops in case
@@ -317,7 +271,6 @@ const subsetEquality = (object, subset) => {
317
271
  if (!isObjectWithKeys(subset)) {
318
272
  return undefined;
319
273
  }
320
-
321
274
  return Object.keys(subset).every(key => {
322
275
  if (isObjectWithKeys(subset[key])) {
323
276
  if (seenReferences.has(subset[key])) {
@@ -325,70 +278,63 @@ const subsetEquality = (object, subset) => {
325
278
  iterableEquality
326
279
  ]);
327
280
  }
328
-
329
281
  seenReferences.set(subset[key], true);
330
282
  }
331
-
332
283
  const result =
333
284
  object != null &&
334
285
  hasPropertyInObject(object, key) &&
335
286
  (0, _jasmineUtils.equals)(object[key], subset[key], [
336
287
  iterableEquality,
337
288
  subsetEqualityWithContext(seenReferences)
338
- ]); // The main goal of using seenReference is to avoid circular node on tree.
289
+ ]);
290
+ // The main goal of using seenReference is to avoid circular node on tree.
339
291
  // It will only happen within a parent and its child, not a node and nodes next to it (same level)
340
292
  // We should keep the reference for a parent and its child only
341
293
  // Thus we should delete the reference immediately so that it doesn't interfere
342
294
  // other nodes within the same level on tree.
343
-
344
295
  seenReferences.delete(subset[key]);
345
296
  return result;
346
297
  });
347
298
  };
348
-
349
299
  return subsetEqualityWithContext()(object, subset);
350
- }; // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
300
+ };
351
301
 
302
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
352
303
  exports.subsetEquality = subsetEquality;
353
-
354
304
  const typeEquality = (a, b) => {
355
305
  if (a == null || b == null || a.constructor === b.constructor) {
356
306
  return undefined;
357
307
  }
358
-
359
308
  return false;
360
309
  };
361
-
362
310
  exports.typeEquality = typeEquality;
363
-
364
311
  const arrayBufferEquality = (a, b) => {
365
312
  if (!(a instanceof ArrayBuffer) || !(b instanceof ArrayBuffer)) {
366
313
  return undefined;
367
314
  }
368
-
369
315
  const dataViewA = new DataView(a);
370
- const dataViewB = new DataView(b); // Buffers are not equal when they do not have the same byte length
316
+ const dataViewB = new DataView(b);
371
317
 
318
+ // Buffers are not equal when they do not have the same byte length
372
319
  if (dataViewA.byteLength !== dataViewB.byteLength) {
373
320
  return false;
374
- } // Check if every byte value is equal to each other
321
+ }
375
322
 
323
+ // Check if every byte value is equal to each other
376
324
  for (let i = 0; i < dataViewA.byteLength; i++) {
377
325
  if (dataViewA.getUint8(i) !== dataViewB.getUint8(i)) {
378
326
  return false;
379
327
  }
380
328
  }
381
-
382
329
  return true;
383
330
  };
384
-
385
331
  exports.arrayBufferEquality = arrayBufferEquality;
386
-
387
332
  const sparseArrayEquality = (a, b) => {
388
333
  if (!Array.isArray(a) || !Array.isArray(b)) {
389
334
  return undefined;
390
- } // A sparse array [, , 1] will have keys ["2"] whereas [undefined, undefined, 1] will have keys ["0", "1", "2"]
335
+ }
391
336
 
337
+ // A sparse array [, , 1] will have keys ["2"] whereas [undefined, undefined, 1] will have keys ["0", "1", "2"]
392
338
  const aKeys = Object.keys(a);
393
339
  const bKeys = Object.keys(b);
394
340
  return (
@@ -396,63 +342,53 @@ const sparseArrayEquality = (a, b) => {
396
342
  (0, _jasmineUtils.equals)(aKeys, bKeys)
397
343
  );
398
344
  };
399
-
400
345
  exports.sparseArrayEquality = sparseArrayEquality;
401
-
402
346
  const partition = (items, predicate) => {
403
347
  const result = [[], []];
404
348
  items.forEach(item => result[predicate(item) ? 0 : 1].push(item));
405
349
  return result;
406
350
  };
407
-
408
351
  exports.partition = partition;
409
-
410
352
  const pathAsArray = propertyPath => {
411
353
  const properties = [];
412
-
413
354
  if (propertyPath === '') {
414
355
  properties.push('');
415
356
  return properties;
416
- } // will match everything that's not a dot or a bracket, and "" for consecutive dots.
357
+ }
417
358
 
418
- const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g'); // Because the regex won't match a dot in the beginning of the path, if present.
359
+ // will match everything that's not a dot or a bracket, and "" for consecutive dots.
360
+ const pattern = RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
419
361
 
362
+ // Because the regex won't match a dot in the beginning of the path, if present.
420
363
  if (propertyPath[0] === '.') {
421
364
  properties.push('');
422
365
  }
423
-
424
366
  propertyPath.replace(pattern, match => {
425
367
  properties.push(match);
426
368
  return match;
427
369
  });
428
370
  return properties;
429
- }; // Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/src/Angular.js#L685-L693
371
+ };
430
372
 
373
+ // Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/src/Angular.js#L685-L693
431
374
  exports.pathAsArray = pathAsArray;
432
-
433
375
  const isError = value => {
434
376
  switch (Object.prototype.toString.call(value)) {
435
377
  case '[object Error]':
436
378
  case '[object Exception]':
437
379
  case '[object DOMException]':
438
380
  return true;
439
-
440
381
  default:
441
382
  return value instanceof Error;
442
383
  }
443
384
  };
444
-
445
385
  exports.isError = isError;
446
-
447
386
  function emptyObject(obj) {
448
387
  return obj && typeof obj === 'object' ? !Object.keys(obj).length : false;
449
388
  }
450
-
451
389
  const MULTILINE_REGEXP = /[\r\n]/;
452
-
453
390
  const isOneline = (expected, received) =>
454
391
  typeof expected === 'string' &&
455
392
  typeof received === 'string' &&
456
393
  (!MULTILINE_REGEXP.test(expected) || !MULTILINE_REGEXP.test(received));
457
-
458
394
  exports.isOneline = isOneline;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jest/expect-utils",
3
- "version": "29.1.2",
3
+ "version": "29.2.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/facebook/jest.git",
@@ -17,11 +17,13 @@
17
17
  "./package.json": "./package.json"
18
18
  },
19
19
  "dependencies": {
20
- "jest-get-type": "^29.0.0"
20
+ "jest-get-type": "^29.2.0"
21
21
  },
22
22
  "devDependencies": {
23
+ "@tsd/typescript": "~4.8.2",
23
24
  "immutable": "^4.0.0",
24
- "jest-matcher-utils": "^29.1.2"
25
+ "jest-matcher-utils": "^29.2.1",
26
+ "tsd-lite": "^0.6.0"
25
27
  },
26
28
  "engines": {
27
29
  "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
@@ -29,5 +31,5 @@
29
31
  "publishConfig": {
30
32
  "access": "public"
31
33
  },
32
- "gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce"
34
+ "gitHead": "4551c0fdd4d25b7206824957c7bcc6baf61e63bf"
33
35
  }