How to use the jest-matcher-utils.RECEIVED_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 / jest-dom / src / utils.js View on Github external
}
    let withType = ''
    try {
      withType = printWithType('Received', received, printReceived)
    } catch (e) {
      // Can throw for Document:
      // https://github.com/jsdom/jsdom/issues/2304
    }
    this.message = [
      matcherHint(
        `${context.isNot ? '.not' : ''}.${matcherFn.name}`,
        'received',
        '',
      ),
      '',
      `${receivedColor(
        'received',
      )} value must be an HTMLElement or an SVGElement.`,
      withType,
    ].join('\n')
  }
}
github testing-library / jest-dom / src / utils.js View on Github external
constructor(received, matcherFn) {
    super()

    /* istanbul ignore next */
    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, matcherFn)
    }
    this.message = [
      received.message,
      '',
      receivedColor(`Failing css:`),
      receivedColor(`${received.css}`),
    ].join('\n')
  }
}
github facebook / jest / packages / expect / src / print.ts View on Github external
const expectedDiffString = receivedDiffString.includes('e')
    ? // toExponential arg is number of digits after the decimal point.
      expectedDiff.toExponential(0)
    : 0 <= precision && precision < 20
    ? // toFixed arg is number of digits after the decimal point.
      // It may be a value between 0 and 20 inclusive.
      // Implementations may optionally support a larger range of values.
      expectedDiff.toFixed(precision + 1)
    : stringify(expectedDiff);

  return (
    `Expected precision:  ${isNot ? '    ' : ''}  ${stringify(precision)}\n` +
    `Expected difference: ${isNot ? 'not ' : ''}< ${EXPECTED_COLOR(
      expectedDiffString,
    )}\n` +
    `Received difference: ${isNot ? '    ' : ''}  ${RECEIVED_COLOR(
      receivedDiffString,
    )}`
  );
};
github testing-library / jest-native / 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 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 Shopify / quilt / packages / react-testing / src / matchers / strings.ts View on Github external
: () =>
        `${matcherHint('.not.toContainReactText', node.toString())}\n\n` +
        `Expected the React element:\n  ${receivedColor(node.toString())}\n` +
        `With text content:\n  ${printReceived(nodeText)}\n` +
        `To contain string:\n  ${printExpected(text)}\n`;
github Shopify / quilt / packages / react-testing / src / matchers / utilities.ts View on Github external
),
    );
  }

  if (
    Array.isArray(node) &&
    node.length > 1 &&
    (node[0] instanceof Root || node[0] instanceof Element)
  ) {
    throw new Error(
      matcherErrorMessage(
        matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
        `${receivedColor(
          'received',
        )} value must be an @shopify/react-testing Root or Element object`,
        `Received an ${receivedColor(
          'array of Root or Element objects',
        )}.\nThis usually means that you passed in the result of \`.findAllX\`. Pass the result of \`.findX\` instead.`,
      ),
    );
  }

  if (!(node instanceof Root) && !(node instanceof Element)) {
    throw new Error(
      matcherErrorMessage(
        matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
        `${receivedColor(
          'received',
        )} value must be an @shopify/react-testing Root or Element object`,
        printWithType('Received', node, printReceived),
      ),
    );
github facebook / jest / packages / jest-matchers / src / extractExpectedAssertionsErrors.js View on Github external
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 Shopify / quilt / packages / ast-utilities / src / matchers.ts View on Github external
: () =>
        `${matcherHint('.toBeFormated', formatedReceived)}\n\n` +
        `Expected:\n  ${receivedColor(formatedReceived)}\n` +
        `To be equal to:\n  ${printExpected(formatedExpected)}\n`;