How to use the jest-matcher-utils.matcherErrorMessage 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 Shopify / quilt / packages / graphql-testing / src / matchers / utilities.ts View on Github external
export function assertIsGraphQL(
  graphQL: unknown,
  {expectation, isNot}: {expectation: string; isNot: boolean},
) {
  if (!(graphQL instanceof GraphQL)) {
    throw new Error(
      matcherErrorMessage(
        matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
        `${receivedColor(
          'received',
        )} value must be a @shopify/graphql-testing GraphQL object`,
        printWithType('Received', graphQL, printReceived),
      ),
    );
  }
}
github Shopify / quilt / packages / react-testing / src / matchers / utilities.ts View on Github external
export function assertIsNode(
  node: unknown,
  {expectation, isNot}: {expectation: string; isNot: boolean},
) {
  if (node == null) {
    throw new Error(
      matcherErrorMessage(
        matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
        `${receivedColor(
          'received',
        )} value must be an @shopify/react-testing Root or Element object`,
        `Received ${receivedColor(
          'null',
        )}.\nThis usually means that your \`.findX\` method failed to find any matching elements.`,
      ),
    );
  }

  if (
    Array.isArray(node) &&
    node.length > 1 &&
    (node[0] instanceof Root || node[0] instanceof Element)
  ) {
github Shopify / quilt / packages / react-testing / src / matchers / utilities.ts View on Github external
export function assertIsType(
  type: unknown,
  {expectation, isNot}: {expectation: string; isNot: boolean},
) {
  if (type == null) {
    throw new Error(
      matcherErrorMessage(
        matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
        `${receivedColor(
          'expected',
        )} value must be a string or a valid React component.`,
        printWithType('Expected', type, printExpected),
      ),
    );
  }
}
github Shopify / quilt / packages / react-testing / src / matchers / utilities.ts View on Github external
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 elastic / elastic-charts / scripts / custom_matchers.ts View on Github external
function toEqualArrayOf(this: jest.MatcherUtils, received: any[], value: any, length?: number) {
  const matcherName = 'toEqualArrayOf';

  if (!Array.isArray(received)) {
    throw new Error(
      matcherErrorMessage(
        this.utils.matcherHint(matcherName),
        `${this.utils.RECEIVED_COLOR('received')} value must be an array.`,
        `Received type: ${typeof received}`,
      ),
    );
  }

  const receivedPretty = this.utils.printReceived(received);
  const elementCheck = received.every((v) => v === value);
  const lengthCheck = length === undefined || received.length === length;

  if (!lengthCheck) {
    return {
      pass: false,
      message: () => `expected array length to be ${length} but got ${received.length}`,
    };