@jest/expect-utils 28.0.0-alpha.0

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