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

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

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

本文整理汇总了TypeScript中jest-matcher-utils.EXPECTED_COLOR函数的典型用法代码示例。如果您正苦于以下问题:TypeScript EXPECTED_COLOR函数的具体用法?TypeScript EXPECTED_COLOR怎么用?TypeScript EXPECTED_COLOR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了EXPECTED_COLOR函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: EXPECTED_COLOR

 report = () =>
   `${RECEIVED_COLOR('Received value')} does not match ` +
   `${EXPECTED_COLOR(`stored snapshot "${result.key}"`)}.\n\n` +
   (diffMessage ||
     EXPECTED_COLOR('- ' + (expected || '')) +
       '\n' +
       RECEIVED_COLOR('+ ' + actual));
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:index.ts


示例2: getState

const extractExpectedAssertionsErrors = () => {
  const result = [];
  const {
    assertionCalls,
    expectedAssertionsNumber,
    expectedAssertionsNumberError,
    isExpectingAssertions,
    isExpectingAssertionsError,
  } = getState();

  resetAssertionsLocalState();

  if (
    typeof expectedAssertionsNumber === 'number' &&
    assertionCalls !== expectedAssertionsNumber
  ) {
    const numOfAssertionsExpected = EXPECTED_COLOR(
      pluralize('assertion', expectedAssertionsNumber),
    );

    expectedAssertionsNumberError.message =
      matcherHint('.assertions', '', String(expectedAssertionsNumber), {
        isDirectExpectCall: true,
      }) +
      '\n\n' +
      `Expected ${numOfAssertionsExpected} to be called but received ` +
      RECEIVED_COLOR(pluralize('assertion call', assertionCalls || 0)) +
      '.';

    result.push({
      actual: assertionCalls,
      error: expectedAssertionsNumberError,
      expected: expectedAssertionsNumber,
    });
  }
  if (isExpectingAssertions && assertionCalls === 0) {
    const expected = EXPECTED_COLOR('at least one assertion');
    const received = RECEIVED_COLOR('received none');

    isExpectingAssertionsError.message =
      matcherHint('.hasAssertions', '', '', {
        isDirectExpectCall: true,
      }) +
      '\n\n' +
      `Expected ${expected} to be called but ${received}.`;

    result.push({
      actual: 'none',
      error: isExpectingAssertionsError,
      expected: 'at least one',
    });
  }

  return result;
};
开发者ID:Volune,项目名称:jest,代码行数:55,代码来源:extractExpectedAssertionsErrors.ts


示例3:

 const report = () =>
   `${RECEIVED_COLOR('Received value')} does not match ` +
   `${EXPECTED_COLOR(`snapshot properties for "${key}"`)}.\n\n` +
   `Expected snapshot to match properties:\n` +
   `  ${context.utils.printExpected(propertyMatchers)}` +
   `\nReceived:\n` +
   `  ${context.utils.printReceived(received)}`;
开发者ID:Volune,项目名称:jest,代码行数:7,代码来源:index.ts


示例4: function

  function(this: MatcherState, received: Function, expected: any) {
    const options = {
      isNot: this.isNot,
      promise: this.promise,
    };

    let thrown = null;

    if (fromPromise && isError(received)) {
      thrown = getThrown(received);
    } else {
      if (typeof received !== 'function') {
        if (!fromPromise) {
          const placeholder = expected === undefined ? '' : 'expected';
          throw new Error(
            matcherErrorMessage(
              matcherHint(matcherName, undefined, placeholder, options),
              `${RECEIVED_COLOR('received')} value must be a function`,
              printWithType('Received', received, printReceived),
            ),
          );
        }
      } else {
        try {
          received();
        } catch (e) {
          thrown = getThrown(e);
        }
      }
    }

    if (expected === undefined) {
      return toThrow(matcherName, options, thrown);
    } else if (typeof expected === 'function') {
      return toThrowExpectedClass(matcherName, options, thrown, expected);
    } else if (typeof expected === 'string') {
      return toThrowExpectedString(matcherName, options, thrown, expected);
    } else if (expected !== null && typeof expected.test === 'function') {
      return toThrowExpectedRegExp(matcherName, options, thrown, expected);
    } else if (
      expected !== null &&
      typeof expected.asymmetricMatch === 'function'
    ) {
      return toThrowExpectedAsymmetric(matcherName, options, thrown, expected);
    } else if (expected !== null && typeof expected === 'object') {
      return toThrowExpectedObject(matcherName, options, thrown, expected);
    } else {
      throw new Error(
        matcherErrorMessage(
          matcherHint(matcherName, undefined, undefined, options),
          `${EXPECTED_COLOR(
            'expected',
          )} value must be a string or regular expression or class or error`,
          printWithType('Expected', expected, printExpected),
        ),
      );
    }
  };
开发者ID:facebook,项目名称:jest,代码行数:58,代码来源:toThrowMatchers.ts


示例5: matcherHint

 ? () =>
     matcherHint('.toBeInstanceOf', 'value', 'constructor', {
       isNot: this.isNot,
     }) +
     '\n\n' +
     `Expected constructor: ${EXPECTED_COLOR(
       constructor.name || String(constructor),
     )}\n` +
     `Received value: ${printReceived(received)}`
开发者ID:Volune,项目名称:jest,代码行数:9,代码来源:matchers.ts


示例6: EXPECTED_COLOR

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)
      }`;
开发者ID:facebook,项目名称:jest,代码行数:15,代码来源:print.ts


示例7: printConstructorName

export const printReceivedConstructorNameNot = (
  label: string,
  received: Function,
  expected: Function,
) =>
  typeof expected.name === 'string' &&
  expected.name.length !== 0 &&
  typeof received.name === 'string' &&
  received.name.length !== 0
    ? printConstructorName(label, received, true, false) +
      ` ${
        Object.getPrototypeOf(received) === expected
          ? 'extends'
          : 'extends … extends'
      } ${EXPECTED_COLOR(expected.name)}` +
      '\n'
    : printConstructorName(label, received, false, false) + '\n';
开发者ID:facebook,项目名称:jest,代码行数:17,代码来源:print.ts


示例8: toBeInstanceOf

    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
            ? printReceivedConstructorNameNot(
开发者ID:facebook,项目名称:jest,代码行数:30,代码来源:matchers.ts


示例9: EXPECTED_COLOR

 report = () =>
   `Snapshot name: ${printName(currentTestName, hint, count)}\n\n` +
   (diffMessage ||
     EXPECTED_COLOR('- ' + (expected || '')) +
       '\n' +
       RECEIVED_COLOR('+ ' + actual));
开发者ID:facebook,项目名称:jest,代码行数:6,代码来源:index.ts


示例10: matcherHint

 : () =>
     matcherHint(matcherName, receivedName, String(expected)) +
     '\n\n' +
     `Expected ${identifier} to have returned ` +
     `${EXPECTED_COLOR(pluralize('time', expected))},` +
     ` but it returned ${RECEIVED_COLOR(pluralize('time', count))}.`;
开发者ID:Volune,项目名称:jest,代码行数:6,代码来源:spyMatchers.ts



注:本文中的jest-matcher-utils.EXPECTED_COLOR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript jest-matcher-utils.RECEIVED_COLOR函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jest-haste-map.ModuleMap类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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