Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getMessage(
matcher,
expectedLabel,
expectedValue,
receivedLabel,
receivedValue,
) {
return [
`${matcher}\n`,
`${expectedLabel}:\n ${expectedColor(expectedValue)}`,
`${receivedLabel}:\n ${receivedColor(receivedValue)}`,
].join('\n')
}
function getMessage(
matcher,
expectedLabel,
expectedValue,
receivedLabel,
receivedValue,
) {
return [
`${matcher}\n`,
`${expectedLabel}:\n${expectedColor(redent(display(expectedValue), 2))}`,
`${receivedLabel}:\n${receivedColor(redent(display(receivedValue), 2))}`,
].join('\n')
}
: () =>
`${`${matcherHint('.toProvideReactContext')}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`To contain context provider:\n ${expectedColor(
printType(Context.Provider),
)}\n${
value ? `With value matching:\n ${printExpected(value)}\n` : ''
}`}${
foundByType.length === 0
? `But no matching ${printType(Context.Provider)}s were found.\n`
: `But the ${
foundByType.length === 1
? 'found provider has'
: 'found provider have'
} had different values:\n\n${diffs(
foundByType,
{value},
this.expand,
)}`
}`;
? () =>
`${matcherHint('.not.toHavePerformedGraphQLOperation')}\n\n` +
`Expected not to have performed GraphQL ${type}:\n ${expectedColor(
name,
)}\n${
variables
? `With variables matching:\n ${printExpected(variables)}\n`
: ''
}` +
`But ${foundByVariables.length} matching ${
foundByVariables.length === 1 ? 'operation was' : 'operations were'
} found.\n`
: () =>
: () =>
[
`${matcherHint('.toContainReactComponentTimes')}\n`,
`Expected the React element:\n ${receivedColor(node.toString())}`,
`To contain component:\n ${expectedColor(printType(type))}`,
`${times} ${pluralize('time', times)}, but it was found ${
foundByProps.length
}.`,
].join('\n');
const extractExpectedAssertionsErrors = () => {
const result = [];
const {
assertionCalls,
expectedAssertionsNumber,
isExpectingAssertions,
} = getState();
setState({assertionCalls: 0, expectedAssertionsNumber: null});
if (
typeof expectedAssertionsNumber === 'number' &&
assertionCalls !== expectedAssertionsNumber
) {
const numOfAssertionsExpected = EXPECTED_COLOR(
pluralize('assertion', expectedAssertionsNumber),
);
const error = new Error(
matcherHint('.assertions', '', String(expectedAssertionsNumber), {
isDirectExpectCall: true,
}) +
'\n\n' +
`Expected ${numOfAssertionsExpected} to be called but only received ` +
RECEIVED_COLOR(pluralize('assertion call', assertionCalls || 0)) +
'.',
);
result.push({
actual: assertionCalls,
error,
expected: expectedAssertionsNumber,
});
matcherHint('.assertions', '', String(expectedAssertionsNumber), {
isDirectExpectCall: true,
}) +
'\n\n' +
`Expected ${numOfAssertionsExpected} to be called but only received ` +
RECEIVED_COLOR(pluralize('assertion call', assertionCalls || 0)) +
'.',
);
result.push({
actual: assertionCalls,
error,
expected: expectedAssertionsNumber,
});
}
if (isExpectingAssertions && assertionCalls === 0) {
const expected = EXPECTED_COLOR('at least one assertion');
const received = RECEIVED_COLOR('received none');
const error = new Error(
matcherHint('.hasAssertions', '', '', {
isDirectExpectCall: true,
}) +
'\n\n' +
`Expected ${expected} to be called but ${received}.`,
);
result.push({
actual: 'none',
error,
expected: 'at least one',
});
}
return result;
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)
}`;