當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jest-matcher-utils.matcherHint函數代碼示例

本文整理匯總了TypeScript中jest-matcher-utils.matcherHint函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript matcherHint函數的具體用法?TypeScript matcherHint怎麽用?TypeScript matcherHint使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了matcherHint函數的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Error

const ensureMock = (mockOrSpy: any, matcherName: any) => {
  if (
    !mockOrSpy ||
    ((mockOrSpy.calls === undefined || mockOrSpy.calls.all === undefined) &&
      mockOrSpy._isMockFunction !== true)
  ) {
    throw new Error(
      matcherErrorMessage(
        matcherHint('[.not]' + matcherName, 'jest.fn()', ''),
        `${RECEIVED_COLOR('received')} value must be a mock or spy function`,
        printWithType('Received', mockOrSpy, printReceived),
      ),
    );
  }
};
開發者ID:Volune,項目名稱:jest,代碼行數:15,代碼來源:spyMatchers.ts

示例2: diff

 : () => {
     const diffString = diff(
       expectedObject,
       getObjectSubset(receivedObject, expectedObject),
       {
         expand: this.expand,
       },
     );
     return (
       matcherHint('.toMatchObject') +
       `\n\nExpected value to match object:\n` +
       `  ${printExpected(expectedObject)}` +
       `\nReceived:\n` +
       `  ${printReceived(receivedObject)}` +
       (diffString ? `\nDifference:\n${diffString}` : '')
     );
   };
開發者ID:Volune,項目名稱:jest,代碼行數:17,代碼來源:matchers.ts

示例3: getLabelPrinter

    const message = () => {
      const labelExpected = 'Expected value';
      const labelReceived = `Received ${getType(received)}`;
      const printLabel = getLabelPrinter(labelExpected, labelReceived);

      return (
        matcherHint(matcherName, undefined, undefined, options) +
        '\n\n' +
        `${printLabel(labelExpected)}${isNot ? 'not ' : ''}${printExpected(
          expected,
        )}\n` +
        `${printLabel(labelReceived)}${isNot ? '    ' : ''}${
          isNot && Array.isArray(received)
            ? printReceivedArrayContainExpectedItem(received, index)
            : printReceived(received)
        }`
      );
    };
開發者ID:facebook,項目名稱:jest,代碼行數:18,代碼來源:matchers.ts

示例4: matcherHint

 : () =>
     matcherHint(matcherName, receivedName) +
     '\n\n' +
     `Expected ${identifier} ${nthString} call to have returned with:\n` +
     `  ${printExpected(expected)}\n` +
     (results.length === 0
       ? `But it was ${RECEIVED_COLOR('not called')}`
       : nth > results.length
       ? `But it was only called ${printReceived(results.length)} times`
       : nthResult.type === 'incomplete'
       ? `But the ${nthString} call ${RECEIVED_COLOR(
           'has not returned yet',
         )}`
       : nthResult.type === 'throw'
       ? `But the ${nthString} call ${RECEIVED_COLOR('threw an error')}`
       : `But the ${nthString} call returned with:\n  ${printReceived(
           nthResult.value,
         )}`);
開發者ID:Volune,項目名稱:jest,代碼行數:18,代碼來源:spyMatchers.ts

示例5: matcherHint

 : () =>
     matcherHint(matcherName, undefined, undefined, options) +
     '\n\n' +
     printExpectedConstructorName('Expected constructor', expected) +
     (thrown === null
       ? '\n' + DID_NOT_THROW
       : (thrown.value != null &&
         typeof thrown.value.constructor === 'function'
           ? printReceivedConstructorName(
               'Received constructor',
               thrown.value.constructor,
             )
           : '') +
         '\n' +
         (thrown.hasMessage
           ? formatReceived('Received message: ', thrown, 'message') +
             formatStack(thrown)
           : formatReceived('Received value: ', thrown, 'value')));
開發者ID:facebook,項目名稱:jest,代碼行數:18,代碼來源:toThrowMatchers.ts

示例6: matcherHint

 : () =>
     matcherHint(matcherName, undefined, expectedArgument, options) +
     '\n\n' +
     `Expected path: ${printExpected(expectedPath)}\n` +
     (hasCompletePath
       ? '\n' +
         printDiffOrStringify(
           expectedValue,
           receivedValue,
           EXPECTED_VALUE_LABEL,
           RECEIVED_VALUE_LABEL,
           isExpand(this.expand),
         )
       : `Received path: ${printReceived(
           expectedPathType === 'array' || receivedPath.length === 0
             ? receivedPath
             : receivedPath.join('.'),
         )}\n\n` +
         (hasValue
           ? `Expected value: ${printExpected(expectedValue)}\n`
           : '') +
         `Received value: ${printReceived(receivedValue)}`);
開發者ID:facebook,項目名稱:jest,代碼行數:22,代碼來源:matchers.ts

示例7: getType

      : () => {
          const receivedType = getType(received);
          const expectedType = getType(expected);
          const suggestToEqual =
            receivedType === expectedType &&
            (receivedType === 'object' || expectedType === 'array') &&
            equals(received, expected, [iterableEquality]);
          const oneline = isOneline(expected, received);
          const diffString = diff(expected, received, {expand: this.expand});

          return (
            matcherHint('.toBe', undefined, undefined, {
              comment,
              isNot: false,
            }) +
            '\n\n' +
            `Expected: ${printExpected(expected)}\n` +
            `Received: ${printReceived(received)}` +
            (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '') +
            (suggestToEqual ? ` ${SUGGEST_TO_EQUAL}` : '')
          );
        };
開發者ID:Volune,項目名稱:jest,代碼行數:22,代碼來源:matchers.ts

示例8: JestAssertionError

): PromiseMatcherFn => (...args) => {
  const options = {
    isNot,
    promise: 'rejects',
  };

  if (!isPromise(actual)) {
    throw new JestAssertionError(
      matcherUtils.matcherErrorMessage(
        matcherUtils.matcherHint(matcherName, undefined, '', options),
        `${matcherUtils.RECEIVED_COLOR('received')} value must be a promise`,
        matcherUtils.printWithType(
          'Received',
          actual,
          matcherUtils.printReceived,
        ),
      ),
    );
  }

  const innerErr = new JestAssertionError();

  return actual.then(
    result => {
      outerErr.message =
        matcherUtils.matcherHint(matcherName, undefined, '', options) +
        '\n\n' +
        `Received promise resolved instead of rejected\n` +
        `Resolved to value: ${matcherUtils.printReceived(result)}`;
      return Promise.reject(outerErr);
    },
    reason =>
      makeThrowingMatcher(matcher, isNot, 'rejects', reason, innerErr).apply(
        null,
        args,
      ),
  );
};
開發者ID:facebook,項目名稱:jest,代碼行數:38,代碼來源:index.ts

示例9: toBeInstanceOf

      `Received:${isNot ? '    ' : ''}    ${printReceived(received)}`;

    return {message, pass};
  },

  toBeInstanceOf(this: MatcherState, received: any, expected: Function) {
    const matcherName = 'toBeInstanceOf';
    const options: MatcherHintOptions = {
      isNot: this.isNot,
      promise: this.promise,
    };

    if (typeof expected !== 'function') {
      throw new Error(
        matcherErrorMessage(
          matcherHint(matcherName, undefined, undefined, options),
          `${EXPECTED_COLOR('expected')} value must be a function`,
          printWithType('Expected', expected, printExpected),
        ),
      );
    }

    const pass = received instanceof expected;

    const message = pass
      ? () =>
          matcherHint(matcherName, undefined, undefined, options) +
          '\n\n' +
          printExpectedConstructorNameNot('Expected constructor', expected) +
          (typeof received.constructor === 'function' &&
          received.constructor !== expected
開發者ID:facebook,項目名稱:jest,代碼行數:31,代碼來源:matchers.ts

示例10: matcherHint

 message: () =>
   matcherHint('.toMatchSnapshot', 'value', '') + '\n\n' + report(),
開發者ID:Volune,項目名稱:jest,代碼行數:2,代碼來源:index.ts

示例11: Error

const _toMatchSnapshot = ({
  context,
  expectedArgument,
  hint,
  inlineSnapshot,
  matcherName,
  options,
  propertyMatchers,
  received,
}: MatchSnapshotConfig) => {
  context.dontThrow && context.dontThrow();
  hint = typeof propertyMatchers === 'string' ? propertyMatchers : hint;

  const {currentTestName, isNot, snapshotState} = context;

  if (isNot) {
    throw new Error(
      matcherHint(matcherName, undefined, expectedArgument, options) +
        '\n\n' +
        NOT_SNAPSHOT_MATCHERS,
    );
  }

  if (!snapshotState) {
    throw new Error(
      matcherHint(matcherName, undefined, expectedArgument, options) +
        '\n\nsnapshot state must be initialized',
    );
  }

  const fullTestName =
    currentTestName && hint
      ? `${currentTestName}: ${hint}`
      : currentTestName || ''; // future BREAKING change: || hint

  if (typeof propertyMatchers === 'object') {
    if (propertyMatchers === null) {
      throw new Error(`Property matchers must be an object.`);
    }
    const propertyPass = context.equals(received, propertyMatchers, [
      context.utils.iterableEquality,
      context.utils.subsetEquality,
    ]);

    if (!propertyPass) {
      const key = snapshotState.fail(fullTestName, received);
      const matched = /(\d+)$/.exec(key);
      const count = matched === null ? 1 : Number(matched[1]);

      const report = () =>
        `Snapshot name: ${printName(currentTestName, hint, count)}\n` +
        '\n' +
        `Expected properties: ${context.utils.printExpected(
          propertyMatchers,
        )}\n` +
        `Received value:      ${context.utils.printReceived(received)}`;

      return {
        message: () =>
          matcherHint(matcherName, undefined, expectedArgument, options) +
          '\n\n' +
          report(),
        name: matcherName,
        pass: false,
        report,
      };
    } else {
      received = utils.deepMerge(received, propertyMatchers);
    }
  }

  const result = snapshotState.match({
    error: context.error,
    inlineSnapshot,
    received,
    testName: fullTestName,
  });
  const {count, pass} = result;
  let {actual, expected} = result;

  let report: () => string;
  if (pass) {
    return {message: () => '', pass: true};
  } else if (!expected) {
    report = () =>
      `New snapshot was ${RECEIVED_COLOR('not written')}. The update flag ` +
      `must be explicitly passed to write a new snapshot.\n\n` +
      `This is likely because this test is run in a continuous integration ` +
      `(CI) environment in which snapshots are not written by default.\n\n` +
      `${RECEIVED_COLOR('Received value')} ` +
      `${actual}`;
  } else {
    expected = (expected || '').trim();
    actual = (actual || '').trim();
    const diffMessage = diff(expected, actual, {
      aAnnotation: 'Snapshot',
      bAnnotation: 'Received',
      expand: snapshotState.expand,
    });

//.........這裏部分代碼省略.........
開發者ID:facebook,項目名稱:jest,代碼行數:101,代碼來源:index.ts

示例12: matcherHint

 const message = () =>
   matcherHint('toBeLessThanOrEqual', undefined, undefined, options) +
   '\n\n' +
   `Expected:${isNot ? ' not' : ''} <= ${printExpected(expected)}\n` +
   `Received:${isNot ? '    ' : ''}    ${printReceived(received)}`;
開發者ID:Volune,項目名稱:jest,代碼行數:5,代碼來源:matchers.ts

示例13: matcherHint

 message: () =>
   matcherHint(matcherName, undefined, expectedArgument, options) +
   '\n\n' +
   report(),
開發者ID:facebook,項目名稱:jest,代碼行數:4,代碼來源:index.ts

示例14:

utils.ensureExpectedIsNumber(66); // $ExpectType void
utils.ensureExpectedIsNumber(66, 'highwayRouteMatcher');
utils.ensureExpectedIsNumber('66', 'highwayRouteMatcher');

utils.ensureNumbers(66, 66); // $ExpectType void
utils.ensureNumbers(66, 66, 'highwayRouteMatcher');
utils.ensureNumbers('66', 'highwayRouteMatcher');
utils.ensureNumbers(66); // $ExpectError

utils.pluralize('fox', 1); // $ExpectType string
utils.pluralize('fox', 9);
utils.pluralize('fox', 'a yuge number'); // $ExpectError
utils.pluralize(1, 2); // $ExpectError

utils.matcherHint('[.not]primeNumberMatcher'); // $ExpectType string
utils.matcherHint('[.not]primeNumberMatcher', '12');
utils.matcherHint('[.not]primeNumberMatcher', '12', '13');
utils.matcherHint('[.not]primeNumberMatcher', '12', '13', {});
utils.matcherHint('[.not]primeNumberMatcher', '12', '13', {
    secondArgument: ''
});
utils.matcherHint('[.not]primeNumberMatcher', '12', '13', {
    secondArgument: '',
    isDirectExpectCall: true
});
utils.matcherHint('[.not]primeNumberMatcher', '12', '13', {
    secondArgument: '',
    isDirectExpectCall: true,
    notAnOption: 'notAnOptionValue' // $ExpectError
});
開發者ID:WorldMaker,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:jest-matcher-utils-tests.ts


注:本文中的jest-matcher-utils.matcherHint函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。