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

Function matcherHint

packages/jest-matcher-utils/src/index.ts:524–587  ·  view source on GitHub ↗
(
  matcherName: string,
  received = 'received',
  expected = 'expected',
  options: MatcherHintOptions = {},
)

Source from the content-addressed store, hash-verified

522// New format: rejects/resolves, not, and matcher name have black color
523// Old format: matcher name has dim color
524export const matcherHint = (
525 matcherName: string,
526 received = 'received',
527 expected = 'expected',
528 options: MatcherHintOptions = {},
529): string => {
530 const {
531 comment = '',
532 expectedColor = EXPECTED_COLOR,
533 isDirectExpectCall = false, // seems redundant with received === ''
534 isNot = false,
535 promise = '',
536 receivedColor = RECEIVED_COLOR,
537 secondArgument = '',
538 secondArgumentColor = EXPECTED_COLOR,
539 } = options;
540 let hint = '';
541 let dimString = 'expect'; // concatenate adjacent dim substrings
542
543 if (!isDirectExpectCall && received !== '') {
544 hint += DIM_COLOR(`${dimString}(`) + receivedColor(received);
545 dimString = ')';
546 }
547
548 if (promise !== '') {
549 hint += DIM_COLOR(`${dimString}.`) + promise;
550 dimString = '';
551 }
552
553 if (isNot) {
554 hint += `${DIM_COLOR(`${dimString}.`)}not`;
555 dimString = '';
556 }
557
558 if (matcherName.includes('.')) {
559 // Old format: for backward compatibility,
560 // especially without promise or isNot options
561 dimString += matcherName;
562 } else {
563 // New format: omit period from matcherName arg
564 hint += DIM_COLOR(`${dimString}.`) + matcherName;
565 dimString = '';
566 }
567
568 if (expected === '') {
569 dimString += '()';
570 } else {
571 hint += DIM_COLOR(`${dimString}(`) + expectedColor(expected);
572 if (secondArgument) {
573 hint += DIM_COLOR(', ') + secondArgumentColor(secondArgument);
574 }
575 dimString = ')';
576 }
577
578 if (comment !== '') {
579 dimString += ` // ${comment}`;
580 }
581

Callers 15

toBeFunction · 0.90
toBeCloseToFunction · 0.90
messageFunction · 0.90
toBeInstanceOfFunction · 0.90
toContainFunction · 0.90
toContainEqualFunction · 0.90
toEqualFunction · 0.90
toHaveLengthFunction · 0.90
toHavePropertyFunction · 0.90
toMatchFunction · 0.90
toMatchObjectFunction · 0.90
toStrictEqualFunction · 0.90

Calls 1

expectedColorFunction · 0.85

Tested by

no test coverage detected