Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
utils.EXPECTED_COLOR; // $ExpectType Chalk
utils.RECEIVED_COLOR; // $ExpectType Chalk
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');
utils.ensureNumbers(66, 66); // $ExpectType void
utils.ensureNumbers(66, 66, 'highwayRouteMatcher');
utils.ensureNumbers('66', 'highwayRouteMatcher');
utils.ensureNumbers(66); // $ExpectError
constructor(received, matcherFn, context) {
super()
/* istanbul ignore next */
if (Error.captureStackTrace) {
Error.captureStackTrace(this, matcherFn)
}
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, context) {
super();
/* istanbul ignore next */
if (Error.captureStackTrace) {
Error.captureStackTrace(this, matcherFn);
}
let withType = '';
try {
withType = printWithType('Received', received, printReceived);
} catch (e) {}
/* istanbul ignore next */
this.message = [
matcherHint(`${context.isNot ? '.not' : ''}.${matcherFn.name}`, 'received', ''),
'',
`${receivedColor('received')} value must be an React Element.`,
withType,
].join('\n');
}
}
export function assertIsGraphQL(
graphQL: unknown,
{expectation, isNot}: {expectation: string; isNot: boolean},
) {
if (!(graphQL instanceof GraphQL)) {
throw new Error(
matcherErrorMessage(
matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
`${receivedColor(
'received',
)} value must be a @shopify/graphql-testing GraphQL object`,
printWithType('Received', graphQL, printReceived),
),
);
}
}
export function assertIsType(
type: unknown,
{expectation, isNot}: {expectation: string; isNot: boolean},
) {
if (type == null) {
throw new Error(
matcherErrorMessage(
matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
`${receivedColor(
'expected',
)} value must be a string or a valid React component.`,
printWithType('Expected', type, printExpected),
),
);
}
}
)} 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),
),
);
}
}
function toHaveFiggyPudding(received, expected) {
if (!isFiggyInstance(received)) {
throw new Error(
`${matcherHint("[.not].toHaveFiggyPudding", "object", "expected")}\n\n` +
`${RECEIVED_COLOR("received")} value must be a FiggyPudding instance.\n${printWithType(
"Received",
received,
printReceived
)}`
);
}
if (!isObjectWithKeys(expected)) {
throw new Error(
`${matcherHint("[.not].toHaveFiggyPudding", "object", "expected")}\n\n` +
`${EXPECTED_COLOR("expected")} value must be an object.\n${printWithType(
"Expected",
expected,
printExpected
)}`
);
}
const pass = hasEveryMatchingProperty(received, expected);
const message = pass
? () =>
`${matcherHint(".not.toHaveFiggyPudding")}\n\n` +
`Expected pudding to not contain:\n` +
` ${printExpected(expected)}\n` +
`Received:\n` +
` ${printReceived(received.toJSON())}`
: () => {
function toHaveFiggyPudding(received, expected) {
if (!isFiggyInstance(received)) {
throw new Error(
`${matcherHint("[.not].toHaveFiggyPudding", "object", "expected")}\n\n` +
`${RECEIVED_COLOR("received")} value must be a FiggyPudding instance.\n${printWithType(
"Received",
received,
printReceived
)}`
);
}
if (!isObjectWithKeys(expected)) {
throw new Error(
`${matcherHint("[.not].toHaveFiggyPudding", "object", "expected")}\n\n` +
`${EXPECTED_COLOR("expected")} value must be an object.\n${printWithType(
"Expected",
expected,
printExpected
)}`
);