• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript jest-matcher-utils.matcherHint函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap