本文整理汇总了TypeScript中jest-get-type.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: diff
// Generate a string that will highlight the difference between two values
// with green and red. (similar to how github does code diffing)
function diff(a: any, b: any, options?: JestDiffOptions): string | null {
if (Object.is(a, b)) {
return NO_DIFF_MESSAGE;
}
const aType = getType(a);
let expectedType = aType;
let omitDifference = false;
if (aType === 'object' && typeof a.asymmetricMatch === 'function') {
if (a.$$typeof !== Symbol.for('jest.asymmetricMatcher')) {
// Do not know expected type of user-defined asymmetric matcher.
return null;
}
if (typeof a.getExpectedType !== 'function') {
// For example, expect.anything() matches either null or undefined
return null;
}
expectedType = a.getExpectedType();
// Primitive types boolean and number omit difference below.
// For example, omit difference for expect.stringMatching(regexp)
omitDifference = expectedType === 'string';
}
if (expectedType !== getType(b)) {
return (
' Comparing two different types of values.' +
` Expected ${chalk.green(expectedType)} but ` +
`received ${chalk.red(getType(b))}.`
);
}
if (omitDifference) {
return null;
}
switch (aType) {
case 'string':
return diffStrings(a, b, options);
case 'boolean':
case 'number':
return comparePrimitive(a, b, options);
case 'map':
return compareObjects(sortMap(a), sortMap(b), options);
case 'set':
return compareObjects(sortSet(a), sortSet(b), options);
default:
return compareObjects(a, b, options);
}
}
开发者ID:Volune,项目名称:jest,代码行数:51,代码来源:index.ts
示例2: getValues
export const errorMessage = (
option: string,
received: any,
defaultValue: any,
options: ValidationOptions,
path?: Array<string>,
): void => {
const conditions = getValues(defaultValue);
const validTypes: Array<string> = Array.from(
new Set(conditions.map(getType)),
);
const message = ` Option ${chalk.bold(
`"${path && path.length > 0 ? path.join('.') + '.' : ''}${option}"`,
)} must be of type:
${validTypes.map(e => chalk.bold.green(e)).join(' or ')}
but instead received:
${chalk.bold.red(getType(received))}
Example:
${formatExamples(option, conditions)}`;
const comment = options.comment;
const name = (options.title && options.title.error) || ERROR;
throw new ValidationError(name, message, comment);
};
开发者ID:Volune,项目名称:jest,代码行数:27,代码来源:errors.ts
示例3: getType
: () => {
const expectedType = getType(expected);
let deepEqualityName = null;
if (expectedType !== 'map' && expectedType !== 'set') {
// If deep equality passes when referential identity fails,
// but exclude map and set until review of their equality logic.
if (equals(received, expected, toStrictEqualTesters, true)) {
deepEqualityName = 'toStrictEqual';
} else if (equals(received, expected, [iterableEquality])) {
deepEqualityName = 'toEqual';
}
}
return (
matcherHint(matcherName, undefined, undefined, options) +
'\n\n' +
(deepEqualityName !== null
? DIM_COLOR(
`If it should pass with deep equality, replace "${matcherName}" with "${deepEqualityName}"`,
) + '\n\n'
: '') +
printDiffOrStringify(
expected,
received,
EXPECTED_LABEL,
RECEIVED_LABEL,
isExpand(this.expand),
)
);
};
开发者ID:facebook,项目名称:jest,代码行数:31,代码来源:matchers.ts
示例4: getLabelPrinter
const message = () => {
const labelExpected = 'Expected length';
const labelReceivedLength = 'Received length';
const labelReceivedValue = `Received ${getType(received)}`;
const printLabel = getLabelPrinter(
labelExpected,
labelReceivedLength,
labelReceivedValue,
);
return (
matcherHint(matcherName, undefined, undefined, options) +
'\n\n' +
`${printLabel(labelExpected)}${isNot ? 'not ' : ''}${printExpected(
expected,
)}\n` +
(isNot
? ''
: `${printLabel(labelReceivedLength)}${printReceived(
received.length,
)}\n`) +
`${printLabel(labelReceivedValue)}${isNot ? ' ' : ''}${printReceived(
received,
)}`
);
};
开发者ID:facebook,项目名称:jest,代码行数:26,代码来源:matchers.ts
示例5: getType
const isDiffable = (expected: unknown, received: unknown): boolean => {
const expectedType = getType(expected);
const receivedType = getType(received);
if (expectedType !== receivedType) {
return false;
}
if (isPrimitive(expected)) {
// Print diff only if both strings have more than one line.
return (
typeof expected === 'string' &&
typeof received === 'string' &&
MULTILINE_REGEXP.test(expected) &&
MULTILINE_REGEXP.test(received)
);
}
if (
expectedType === 'date' ||
expectedType === 'function' ||
expectedType === 'regexp'
) {
return false;
}
if (expected instanceof Error && received instanceof Error) {
return false;
}
if (
expectedType === 'object' &&
typeof (expected as any).asymmetricMatch === 'function'
) {
return false;
}
if (
receivedType === 'object' &&
typeof (received as any).asymmetricMatch === 'function'
) {
return false;
}
return true;
};
开发者ID:facebook,项目名称:jest,代码行数:46,代码来源:index.ts
示例6: createReporterError
export function createReporterError(
reporterIndex: number,
reporterValue: Array<Config.ReporterConfig> | string,
) {
const errorMessage =
` Reporter at index ${reporterIndex} must be of type:\n` +
` ${chalk.bold.green(validReporterTypes.join(' or '))}\n` +
` but instead received:\n` +
` ${chalk.bold.red(getType(reporterValue))}`;
return new ValidationError(ERROR, errorMessage, DOCUMENTATION_NOTE);
}
开发者ID:Volune,项目名称:jest,代码行数:12,代码来源:ReporterValidationErrors.ts
示例7: getType
export const printWithType = (
name: string, // 'Expected' or 'Received'
value: unknown,
print: (value: unknown) => string, // printExpected or printReceived
) => {
const type = getType(value);
const hasType =
type !== 'null' && type !== 'undefined'
? `${name} has type: ${type}\n`
: '';
const hasValue = `${name} has value: ${print(value)}`;
return hasType + hasValue;
};
开发者ID:Volune,项目名称:jest,代码行数:13,代码来源:index.ts
示例8: 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
注:本文中的jest-get-type.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论