本文整理汇总了TypeScript中jest-matcher-utils.diff函数的典型用法代码示例。如果您正苦于以下问题:TypeScript diff函数的具体用法?TypeScript diff怎么用?TypeScript diff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了diff函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: diff
: () => {
const diffString =
valuePassed && hasEndProp
? diff(value, result.value, {expand: this.expand})
: '';
return (
matcherHint('.toHaveProperty', 'object', 'path', {
secondArgument,
} as MatcherHintOptions) +
'\n\n' +
`Expected the object:\n` +
` ${printReceived(object)}\n` +
`To have a nested property:\n` +
` ${printExpected(keyPath)}\n` +
(valuePassed
? `With a value of:\n ${printExpected(value)}\n`
: '') +
(hasEndProp
? `Received:\n` +
` ${printReceived(result.value)}` +
(diffString ? `\n\nDifference:\n\n${diffString}` : '')
: traversedPath
? `Received:\n ${RECEIVED_COLOR(
'object',
)}.${traversedPath}: ${printReceived(lastTraversedObject)}`
: '')
);
};
开发者ID:Volune,项目名称:jest,代码行数:28,代码来源:matchers.ts
示例2: assertionErrorMessage
function assertionErrorMessage(
error: AssertionErrorWithStack,
options: DiffOptions,
) {
const {expected, actual, generatedMessage, message, operator, stack} = error;
const diffString = diff(expected, actual, options);
const hasCustomMessage = !generatedMessage;
const operatorName = getOperatorName(operator, stack);
const trimmedStack = stack
.replace(message, '')
.replace(/AssertionError(.*)/g, '');
if (operatorName === 'doesNotThrow') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
chalk.reset(`Expected the function not to throw an error.\n`) +
chalk.reset(`Instead, it threw:\n`) +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
trimmedStack
);
}
if (operatorName === 'throws') {
return (
assertThrowingMatcherHint(operatorName) +
'\n\n' +
chalk.reset(`Expected the function to throw an error.\n`) +
chalk.reset(`But it didn't throw anything.`) +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
trimmedStack
);
}
return (
assertMatcherHint(operator, operatorName) +
'\n\n' +
chalk.reset(`Expected value ${operatorMessage(operator)}`) +
` ${printExpected(expected)}\n` +
chalk.reset(`Received:\n`) +
` ${printReceived(actual)}` +
chalk.reset(hasCustomMessage ? '\n\nMessage:\n ' + message : '') +
(diffString ? `\n\nDifference:\n\n${diffString}` : '') +
trimmedStack
);
}
开发者ID:Volune,项目名称:jest,代码行数:47,代码来源:assertionErrorMessage.ts
示例3: 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
示例4: isOneline
const formatMismatchedArgs = (expected: any, received: any): string => {
const length = Math.max(expected.length, received.length);
const printedArgs = [];
for (let i = 0; i < length; i++) {
if (!equals(expected[i], received[i], [iterableEquality])) {
const oneline = isOneline(expected[i], received[i]);
const diffString = diff(expected[i], received[i]);
printedArgs.push(
` ${printExpected(expected[i])}\n` +
`as argument ${i + 1}, but it was called with\n` +
` ${printReceived(received[i])}.` +
(diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : ''),
);
} else if (i >= expected.length) {
printedArgs.push(
` Did not expect argument ${i + 1} ` +
`but it was called with ${printReceived(received[i])}.`,
);
}
}
return printedArgs.join('\n');
};
开发者ID:Volune,项目名称:jest,代码行数:24,代码来源:spyMatchers.ts
注:本文中的jest-matcher-utils.diff函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论