本文整理匯總了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)}`
: '')
);
};
示例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
);
}
示例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}` : '')
);
};
示例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');
};