Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
let withType = ''
try {
withType = printWithType('Received', received, printReceived)
} catch (e) {
// Can throw for Document:
// https://github.com/jsdom/jsdom/issues/2304
}
this.message = [
matcherHint(
`${context.isNot ? '.not' : ''}.${matcherFn.name}`,
'received',
'',
),
'',
`${receivedColor(
'received',
)} value must be an HTMLElement or an SVGElement.`,
withType,
].join('\n')
}
}
constructor(received, matcherFn) {
super()
/* istanbul ignore next */
if (Error.captureStackTrace) {
Error.captureStackTrace(this, matcherFn)
}
this.message = [
received.message,
'',
receivedColor(`Failing css:`),
receivedColor(`${received.css}`),
].join('\n')
}
}
const expectedDiffString = receivedDiffString.includes('e')
? // toExponential arg is number of digits after the decimal point.
expectedDiff.toExponential(0)
: 0 <= precision && precision < 20
? // toFixed arg is number of digits after the decimal point.
// It may be a value between 0 and 20 inclusive.
// Implementations may optionally support a larger range of values.
expectedDiff.toFixed(precision + 1)
: stringify(expectedDiff);
return (
`Expected precision: ${isNot ? ' ' : ''} ${stringify(precision)}\n` +
`Expected difference: ${isNot ? 'not ' : ''}< ${EXPECTED_COLOR(
expectedDiffString,
)}\n` +
`Received difference: ${isNot ? ' ' : ''} ${RECEIVED_COLOR(
receivedDiffString,
)}`
);
};
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');
}
function getMessage(
matcher,
expectedLabel,
expectedValue,
receivedLabel,
receivedValue,
) {
return [
`${matcher}\n`,
`${expectedLabel}:\n ${expectedColor(expectedValue)}`,
`${receivedLabel}:\n ${receivedColor(receivedValue)}`,
].join('\n')
}
: () =>
`${matcherHint('.not.toContainReactText', node.toString())}\n\n` +
`Expected the React element:\n ${receivedColor(node.toString())}\n` +
`With text content:\n ${printReceived(nodeText)}\n` +
`To contain string:\n ${printExpected(text)}\n`;
),
);
}
if (
Array.isArray(node) &&
node.length > 1 &&
(node[0] instanceof Root || node[0] instanceof Element)
) {
throw new Error(
matcherErrorMessage(
matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
`${receivedColor(
'received',
)} value must be an @shopify/react-testing Root or Element object`,
`Received an ${receivedColor(
'array of Root or Element objects',
)}.\nThis usually means that you passed in the result of \`.findAllX\`. Pass the result of \`.findX\` instead.`,
),
);
}
if (!(node instanceof Root) && !(node instanceof Element)) {
throw new Error(
matcherErrorMessage(
matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
`${receivedColor(
'received',
)} value must be an @shopify/react-testing Root or Element object`,
printWithType('Received', node, printReceived),
),
);
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;
};
: () =>
`${matcherHint('.toBeFormated', formatedReceived)}\n\n` +
`Expected:\n ${receivedColor(formatedReceived)}\n` +
`To be equal to:\n ${printExpected(formatedExpected)}\n`;