本文整理匯總了TypeScript中jest-matcher-utils.stringify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript stringify函數的具體用法?TypeScript stringify怎麽用?TypeScript stringify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了stringify函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: matcherHint
? () =>
matcherHint(matcherName, undefined, undefined, options) +
'\n\n' +
`Expected: not ${printExpected(expected)}\n` +
(stringify(expected) !== stringify(received)
? `Received: ${printReceived(received)}`
: '')
示例2: Error
const _validateResult = (result: any) => {
if (
typeof result !== 'object' ||
typeof result.pass !== 'boolean' ||
(result.message &&
(typeof result.message !== 'string' &&
typeof result.message !== 'function'))
) {
throw new Error(
'Unexpected return from a matcher function.\n' +
'Matcher functions should ' +
'return an object in the following format:\n' +
' {message?: string | function, pass: boolean}\n' +
`'${matcherUtils.stringify(result)}' was returned`,
);
}
};
示例3:
import * as chalk from 'chalk';
import * as utils from 'jest-matcher-utils';
utils.EXPECTED_COLOR; // $ExpectType ChalkChain
utils.RECEIVED_COLOR; // $ExpectType ChalkChain
utils.SUGGEST_TO_EQUAL; // $ExpectType string
utils.stringify({}); // $ExpectType string
utils.stringify({}, 44);
utils.stringify({}, '44'); // $ExpectError
utils.stringify({}, false); // $ExpectError
utils.highlightTrailingWhitespace('', chalk.red); // $ExpectType string
utils.highlightTrailingWhitespace(44, chalk.blue); // $ExpectError
utils.highlightTrailingWhitespace(false, chalk.green); // $ExpectError
utils.printReceived({}); // $ExpectType string
utils.printExpected({}); // $ExpectType string
utils.printWithType('obj', {}, () => ''); // $ExpectType string
utils.ensureNoExpected(null, ''); // $ExpectType void
utils.ensureNoExpected('', '');
utils.ensureActualIsNumber(66); // $ExpectType void
utils.ensureActualIsNumber(66, 'highwayRouteMatcher');
utils.ensureActualIsNumber('66', 'highwayRouteMatcher');
utils.ensureExpectedIsNumber(66); // $ExpectType void
utils.ensureExpectedIsNumber(66, 'highwayRouteMatcher');
utils.ensureExpectedIsNumber('66', 'highwayRouteMatcher');
示例4: stringify
.map((item, i) => {
const stringified = stringify(item);
return i === index ? INVERTED_COLOR(stringified) : stringified;
})