MCPcopy
hub / github.com/jestjs/jest / toEqual

Function toEqual

packages/expect/src/matchers.ts:616–654  ·  packages/expect/src/matchers.ts::toEqual
(received: unknown, expected: unknown)

Source from the content-addressed store, hash-verified

614 },
615
616 toEqual(received: unknown, expected: unknown) {
617 const matcherName = class="st">'toEqual';
618 const options: MatcherHintOptions = {
619 comment: class="st">'deep equality',
620 isNot: this.isNot,
621 promise: this.promise,
622 };
623
624 const pass = equals(received, expected, [
625 ...this.customTesters,
626 iterableEquality,
627 ]);
628
629 const message = pass
630 ? () =>
631 class="cm">// eslint-disable-next-line prefer-template
632 matcherHint(matcherName, undefined, undefined, options) +
633 class="st">'\n\n' +
634 `Expected: not ${printExpected(expected)}\n` +
635 (stringify(expected) === stringify(received)
636 ? class="st">''
637 : `Received: ${printReceived(received)}`)
638 : () =>
639 class="cm">// eslint-disable-next-line prefer-template
640 matcherHint(matcherName, undefined, undefined, options) +
641 class="st">'\n\n' +
642 printDiffOrStringify(
643 expected,
644 received,
645 EXPECTED_LABEL,
646 RECEIVED_LABEL,
647 isExpand(this.expand),
648 );
649
650 class="cm">// Passing the actual and expected objects so that a custom reporter
651 class="cm">// could access them, for example in order to display a custom visual diff,
652 class="cm">// or create a different error message
653 return {actual: received, expected, message, name: matcherName, pass};
654 },
655
656 toHaveLength(received: any, expected: number) {
657 const matcherName = class="st">'toHaveLength';

Callers

nothing calls this directly

Calls 7

equalsFunction · 0.90
matcherHintFunction · 0.90
printExpectedFunction · 0.90
stringifyFunction · 0.90
printReceivedFunction · 0.90
printDiffOrStringifyFunction · 0.90
isExpandFunction · 0.70

Tested by

no test coverage detected