How to use the jest-matcher-utils.EXPECTED_COLOR function in jest-matcher-utils

To help you get started, we’ve selected a few jest-matcher-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github testing-library / dom-testing-library / src / jest-extensions.js View on Github external
function getMessage(
  matcher,
  expectedLabel,
  expectedValue,
  receivedLabel,
  receivedValue,
) {
  return [
    `${matcher}\n`,
    `${expectedLabel}:\n  ${expectedColor(expectedValue)}`,
    `${receivedLabel}:\n  ${receivedColor(receivedValue)}`,
  ].join('\n')
}
github testing-library / jest-dom / src / utils.js View on Github external
function getMessage(
  matcher,
  expectedLabel,
  expectedValue,
  receivedLabel,
  receivedValue,
) {
  return [
    `${matcher}\n`,
    `${expectedLabel}:\n${expectedColor(redent(display(expectedValue), 2))}`,
    `${receivedLabel}:\n${receivedColor(redent(display(receivedValue), 2))}`,
  ].join('\n')
}
github Shopify / quilt / packages / react-testing / src / matchers / context.ts View on Github external
: () =>
        `${`${matcherHint('.toProvideReactContext')}\n\n` +
          `Expected the React element:\n  ${receivedColor(node.toString())}\n` +
          `To contain context provider:\n  ${expectedColor(
            printType(Context.Provider),
          )}\n${
            value ? `With value matching:\n  ${printExpected(value)}\n` : ''
          }`}${
          foundByType.length === 0
            ? `But no matching ${printType(Context.Provider)}s were found.\n`
            : `But the ${
                foundByType.length === 1
                  ? 'found provider has'
                  : 'found provider have'
              } had different values:\n\n${diffs(
                foundByType,
                {value},
                this.expand,
              )}`
        }`;
github Shopify / quilt / packages / graphql-testing / src / matchers / operations.ts View on Github external
? () =>
        `${matcherHint('.not.toHavePerformedGraphQLOperation')}\n\n` +
        `Expected not to have performed GraphQL ${type}:\n  ${expectedColor(
          name,
        )}\n${
          variables
            ? `With variables matching:\n  ${printExpected(variables)}\n`
            : ''
        }` +
        `But ${foundByVariables.length} matching ${
          foundByVariables.length === 1 ? 'operation was' : 'operations were'
        } found.\n`
    : () =>
github Shopify / quilt / packages / react-testing / src / matchers / components.ts View on Github external
: () =>
        [
          `${matcherHint('.toContainReactComponentTimes')}\n`,
          `Expected the React element:\n  ${receivedColor(node.toString())}`,
          `To contain component:\n  ${expectedColor(printType(type))}`,
          `${times} ${pluralize('time', times)}, but it was found ${
            foundByProps.length
          }.`,
        ].join('\n');
github facebook / jest / packages / jest-matchers / src / extractExpectedAssertionsErrors.js View on Github external
const extractExpectedAssertionsErrors = () => {
  const result = [];
  const {
    assertionCalls,
    expectedAssertionsNumber,
    isExpectingAssertions,
  } = getState();
  setState({assertionCalls: 0, expectedAssertionsNumber: null});
  if (
    typeof expectedAssertionsNumber === 'number' &&
    assertionCalls !== expectedAssertionsNumber
  ) {
    const numOfAssertionsExpected = EXPECTED_COLOR(
      pluralize('assertion', expectedAssertionsNumber),
    );
    const error = new Error(
      matcherHint('.assertions', '', String(expectedAssertionsNumber), {
        isDirectExpectCall: true,
      }) +
        '\n\n' +
        `Expected ${numOfAssertionsExpected} to be called but only received ` +
        RECEIVED_COLOR(pluralize('assertion call', assertionCalls || 0)) +
        '.',
    );
    result.push({
      actual: assertionCalls,
      error,
      expected: expectedAssertionsNumber,
    });
github facebook / jest / packages / jest-matchers / src / extractExpectedAssertionsErrors.js View on Github external
matcherHint('.assertions', '', String(expectedAssertionsNumber), {
        isDirectExpectCall: true,
      }) +
        '\n\n' +
        `Expected ${numOfAssertionsExpected} to be called but only received ` +
        RECEIVED_COLOR(pluralize('assertion call', assertionCalls || 0)) +
        '.',
    );
    result.push({
      actual: assertionCalls,
      error,
      expected: expectedAssertionsNumber,
    });
  }
  if (isExpectingAssertions && assertionCalls === 0) {
    const expected = EXPECTED_COLOR('at least one assertion');
    const received = RECEIVED_COLOR('received none');
    const error = new Error(
      matcherHint('.hasAssertions', '', '', {
        isDirectExpectCall: true,
      }) +
        '\n\n' +
        `Expected ${expected} to be called but ${received}.`,
    );
    result.push({
      actual: 'none',
      error,
      expected: 'at least one',
    });
  }

  return result;
github facebook / jest / packages / expect / src / print.ts View on Github external
const printConstructorName = (
  label: string,
  constructor: Function,
  isNot: boolean,
  isExpected: boolean,
): string =>
  typeof constructor.name !== 'string'
    ? `${label} name is not a string`
    : constructor.name.length === 0
    ? `${label} name is an empty string`
    : `${label}: ${!isNot ? '' : isExpected ? 'not ' : '    '}${
        isExpected
          ? EXPECTED_COLOR(constructor.name)
          : RECEIVED_COLOR(constructor.name)
      }`;