@jest/expect-utils
Advanced tools
Comparing version 29.3.1 to 29.4.0
@@ -26,12 +26,6 @@ /** | ||
subset: any, | ||
customTesters?: Array<Tester>, | ||
seenReferences?: WeakMap<object, boolean>, | ||
) => any; | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
declare type GetPath = { | ||
@@ -62,2 +56,3 @@ hasEndProp?: boolean; | ||
b: any, | ||
customTesters?: Array<Tester>, | ||
aStack?: Array<any>, | ||
@@ -77,2 +72,3 @@ bStack?: Array<any>, | ||
b: unknown, | ||
customTesters?: Array<Tester>, | ||
) => boolean | undefined; | ||
@@ -83,15 +79,18 @@ | ||
subset: unknown, | ||
customTesters?: Array<Tester>, | ||
) => boolean | undefined; | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
export declare type Tester = (a: any, b: any) => boolean | undefined; | ||
export declare type Tester = ( | ||
this: TesterContext, | ||
a: any, | ||
b: any, | ||
customTesters: Array<Tester>, | ||
) => boolean | undefined; | ||
export declare interface TesterContext { | ||
equals: EqualsFunction; | ||
} | ||
export declare const typeEquality: (a: any, b: any) => boolean | undefined; | ||
export {}; |
@@ -63,4 +63,12 @@ 'use strict'; | ||
} | ||
const testerContext = { | ||
equals | ||
}; | ||
for (let i = 0; i < customTesters.length; i++) { | ||
const customTesterResult = customTesters[i](a, b); | ||
const customTesterResult = customTesters[i].call( | ||
testerContext, | ||
a, | ||
b, | ||
customTesters | ||
); | ||
if (customTesterResult !== undefined) { | ||
@@ -67,0 +75,0 @@ return customTesterResult; |
@@ -84,3 +84,8 @@ 'use strict'; | ||
exports.getPath = getPath; | ||
const getObjectSubset = (object, subset, seenReferences = new WeakMap()) => { | ||
const getObjectSubset = ( | ||
object, | ||
subset, | ||
customTesters = [], | ||
seenReferences = new WeakMap() | ||
) => { | ||
/* eslint-enable @typescript-eslint/explicit-module-boundary-types */ | ||
@@ -90,3 +95,5 @@ if (Array.isArray(object)) { | ||
// The map method returns correct subclass of subset. | ||
return subset.map((sub, i) => getObjectSubset(object[i], sub)); | ||
return subset.map((sub, i) => | ||
getObjectSubset(object[i], sub, customTesters) | ||
); | ||
} | ||
@@ -98,2 +105,3 @@ } else if (object instanceof Date) { | ||
(0, _jasmineUtils.equals)(object, subset, [ | ||
...customTesters, | ||
iterableEquality, | ||
@@ -113,3 +121,8 @@ subsetEquality | ||
? seenReferences.get(object[key]) | ||
: getObjectSubset(object[key], subset[key], seenReferences); | ||
: getObjectSubset( | ||
object[key], | ||
subset[key], | ||
customTesters, | ||
seenReferences | ||
); | ||
}); | ||
@@ -129,3 +142,4 @@ if (Object.keys(trimmed).length > 0) { | ||
a, | ||
b /* eslint-enable @typescript-eslint/explicit-module-boundary-types */, | ||
b, | ||
customTesters = [] /* eslint-enable @typescript-eslint/explicit-module-boundary-types */, | ||
aStack = [], | ||
@@ -160,3 +174,16 @@ bStack = [] | ||
const iterableEqualityWithStack = (a, b) => | ||
iterableEquality(a, b, [...aStack], [...bStack]); | ||
iterableEquality( | ||
a, | ||
b, | ||
[...filteredCustomTesters], | ||
[...aStack], | ||
[...bStack] | ||
); | ||
// Replace any instance of iterableEquality with the new | ||
// iterableEqualityWithStack so we can do circular detection | ||
const filteredCustomTesters = [ | ||
...customTesters.filter(t => t !== iterableEquality), | ||
iterableEqualityWithStack | ||
]; | ||
if (a.size !== undefined) { | ||
@@ -174,5 +201,7 @@ if (a.size !== b.size) { | ||
for (const bValue of b) { | ||
const isEqual = (0, _jasmineUtils.equals)(aValue, bValue, [ | ||
iterableEqualityWithStack | ||
]); | ||
const isEqual = (0, _jasmineUtils.equals)( | ||
aValue, | ||
bValue, | ||
filteredCustomTesters | ||
); | ||
if (isEqual === true) { | ||
@@ -200,16 +229,22 @@ has = true; | ||
!b.has(aEntry[0]) || | ||
!(0, _jasmineUtils.equals)(aEntry[1], b.get(aEntry[0]), [ | ||
iterableEqualityWithStack | ||
]) | ||
!(0, _jasmineUtils.equals)( | ||
aEntry[1], | ||
b.get(aEntry[0]), | ||
filteredCustomTesters | ||
) | ||
) { | ||
let has = false; | ||
for (const bEntry of b) { | ||
const matchedKey = (0, _jasmineUtils.equals)(aEntry[0], bEntry[0], [ | ||
iterableEqualityWithStack | ||
]); | ||
const matchedKey = (0, _jasmineUtils.equals)( | ||
aEntry[0], | ||
bEntry[0], | ||
filteredCustomTesters | ||
); | ||
let matchedValue = false; | ||
if (matchedKey === true) { | ||
matchedValue = (0, _jasmineUtils.equals)(aEntry[1], bEntry[1], [ | ||
iterableEqualityWithStack | ||
]); | ||
matchedValue = (0, _jasmineUtils.equals)( | ||
aEntry[1], | ||
bEntry[1], | ||
filteredCustomTesters | ||
); | ||
} | ||
@@ -237,5 +272,3 @@ if (matchedValue === true) { | ||
nextB.done || | ||
!(0, _jasmineUtils.equals)(aValue, nextB.value, [ | ||
iterableEqualityWithStack | ||
]) | ||
!(0, _jasmineUtils.equals)(aValue, nextB.value, filteredCustomTesters) | ||
) { | ||
@@ -273,3 +306,5 @@ return false; | ||
!(a instanceof Date); | ||
const subsetEquality = (object, subset) => { | ||
const subsetEquality = (object, subset, customTesters = []) => { | ||
const filteredCustomTesters = customTesters.filter(t => t !== subsetEquality); | ||
// subsetEquality needs to keep track of the references | ||
@@ -284,8 +319,10 @@ // it has already visited to avoid infinite loops in case | ||
} | ||
return Object.keys(subset).every(key => { | ||
return Reflect.ownKeys(subset).every(key => { | ||
if (isObjectWithKeys(subset[key])) { | ||
if (seenReferences.has(subset[key])) { | ||
return (0, _jasmineUtils.equals)(object[key], subset[key], [ | ||
iterableEquality | ||
]); | ||
return (0, _jasmineUtils.equals)( | ||
object[key], | ||
subset[key], | ||
filteredCustomTesters | ||
); | ||
} | ||
@@ -298,3 +335,3 @@ seenReferences.set(subset[key], true); | ||
(0, _jasmineUtils.equals)(object[key], subset[key], [ | ||
iterableEquality, | ||
...filteredCustomTesters, | ||
subsetEqualityWithContext(seenReferences) | ||
@@ -344,3 +381,3 @@ ]); | ||
exports.arrayBufferEquality = arrayBufferEquality; | ||
const sparseArrayEquality = (a, b) => { | ||
const sparseArrayEquality = (a, b, customTesters = []) => { | ||
if (!Array.isArray(a) || !Array.isArray(b)) { | ||
@@ -354,4 +391,8 @@ return undefined; | ||
return ( | ||
(0, _jasmineUtils.equals)(a, b, [iterableEquality, typeEquality], true) && | ||
(0, _jasmineUtils.equals)(aKeys, bKeys) | ||
(0, _jasmineUtils.equals)( | ||
a, | ||
b, | ||
customTesters.filter(t => t !== sparseArrayEquality), | ||
true | ||
) && (0, _jasmineUtils.equals)(aKeys, bKeys) | ||
); | ||
@@ -358,0 +399,0 @@ }; |
{ | ||
"name": "@jest/expect-utils", | ||
"version": "29.3.1", | ||
"version": "29.4.0", | ||
"repository": { | ||
@@ -23,5 +23,5 @@ "type": "git", | ||
"devDependencies": { | ||
"@tsd/typescript": "~4.8.2", | ||
"@tsd/typescript": "^4.9.0", | ||
"immutable": "^4.0.0", | ||
"jest-matcher-utils": "^29.3.1", | ||
"jest-matcher-utils": "^29.4.0", | ||
"tsd-lite": "^0.6.0" | ||
@@ -35,3 +35,3 @@ }, | ||
}, | ||
"gitHead": "05deb8393c4ad71e19be2567b704dfd3a2ab5fc9" | ||
"gitHead": "4bc0e8acaf990e6618a7bed1dca67760c20bb12a" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55665
10
800