MCPcopy
hub / github.com/vitest-dev/vitest / subsetEqualityWithContext

Function subsetEqualityWithContext

packages/expect/src/jest-utils.ts:619–648  ·  view source on GitHub ↗
(seenReferences: WeakMap<object, boolean> = new WeakMap())

Source from the content-addressed store, hash-verified

617 // there are circular references in the subset passed to it.
618 const subsetEqualityWithContext
619 = (seenReferences: WeakMap<object, boolean> = new WeakMap()) =>
620 (object: any, subset: any): boolean | undefined => {
621 if (!isObjectWithKeys(subset)) {
622 return undefined
623 }
624
625 return Object.keys(subset).every((key) => {
626 if (subset[key] != null && typeof subset[key] === 'object') {
627 if (seenReferences.has(subset[key])) {
628 return equals(object[key], subset[key], filteredCustomTesters)
629 }
630
631 seenReferences.set(subset[key], true)
632 }
633 const result
634 = object != null
635 && hasPropertyInObject(object, key)
636 && equals(object[key], subset[key], [
637 ...filteredCustomTesters,
638 subsetEqualityWithContext(seenReferences),
639 ])
640 // The main goal of using seenReference is to avoid circular node on tree.
641 // It will only happen within a parent and its child, not a node and nodes next to it (same level)
642 // We should keep the reference for a parent and its child only
643 // Thus we should delete the reference immediately so that it doesn't interfere
644 // other nodes within the same level on tree.
645 seenReferences.delete(subset[key])
646 return result
647 })
648 }
649
650 return subsetEqualityWithContext()(object, subset)
651}

Callers 1

subsetEqualityFunction · 0.85

Calls 7

isObjectWithKeysFunction · 0.85
equalsFunction · 0.85
hasPropertyInObjectFunction · 0.85
keysMethod · 0.80
hasMethod · 0.45
setMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected