本文整理汇总了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));
示例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;
};
示例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)}`;
示例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),
),
);
}
};
示例5: matcherHint
? () =>
matcherHint('.toBeInstanceOf', 'value', 'constructor', {
isNot: this.isNot,
}) +
'\n\n' +
`Expected constructor: ${EXPECTED_COLOR(
constructor.name || String(constructor),
)}\n` +
`Received value: ${printReceived(received)}`
示例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)
}`;
示例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';
示例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(
示例9: EXPECTED_COLOR
report = () =>
`Snapshot name: ${printName(currentTestName, hint, count)}\n\n` +
(diffMessage ||
EXPECTED_COLOR('- ' + (expected || '')) +
'\n' +
RECEIVED_COLOR('+ ' + actual));
示例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))}.`;