本文整理汇总了TypeScript中jest-matcher-utils.RECEIVED_COLOR函数的典型用法代码示例。如果您正苦于以下问题:TypeScript RECEIVED_COLOR函数的具体用法?TypeScript RECEIVED_COLOR怎么用?TypeScript RECEIVED_COLOR使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RECEIVED_COLOR函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Error
const ensureMock = (mockOrSpy: any, matcherName: any) => {
if (
!mockOrSpy ||
((mockOrSpy.calls === undefined || mockOrSpy.calls.all === undefined) &&
mockOrSpy._isMockFunction !== true)
) {
throw new Error(
matcherErrorMessage(
matcherHint('[.not]' + matcherName, 'jest.fn()', ''),
`${RECEIVED_COLOR('received')} value must be a mock or spy function`,
printWithType('Received', mockOrSpy, printReceived),
),
);
}
};
示例2:
report = () =>
`New snapshot was ${RECEIVED_COLOR('not written')}. The update flag ` +
`must be explicitly passed to write a new snapshot.\n\n` +
`This is likely because this test is run in a continuous integration ` +
`(CI) environment in which snapshots are not written by default.\n\n` +
`${RECEIVED_COLOR('Received value')} ` +
`${actual}`;
示例3: 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));
示例4: 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;
};
示例5: matcherHint
: () =>
matcherHint(matcherName, receivedName) +
'\n\n' +
`Expected ${identifier} to have last returned:\n` +
` ${printExpected(expected)}\n` +
(!lastResult
? `But it was ${RECEIVED_COLOR('not called')}`
: lastResult.type === 'incomplete'
? `But the last call ${RECEIVED_COLOR('has not returned yet')}`
: lastResult.type === 'throw'
? `But the last call ${RECEIVED_COLOR('threw an error')}`
: `But the last call returned:\n ${printReceived(
lastResult.value,
)}`);
示例6: 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)}`
: '')
);
};
示例7: 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),
),
);
}
};
示例8: RECEIVED_COLOR
export const printReceivedStringContainExpectedSubstring = (
received: string,
start: number,
length: number, // not end
): string =>
RECEIVED_COLOR(
'"' +
printSubstring(received.slice(0, start)) +
INVERTED_COLOR(printSubstring(received.slice(start, start + length))) +
printSubstring(received.slice(start + length)) +
'"',
);