Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 assertIsNode(
node: unknown,
{expectation, isNot}: {expectation: string; isNot: boolean},
) {
if (node == null) {
throw new Error(
matcherErrorMessage(
matcherHint(`.${expectation}`, undefined, undefined, {isNot}),
`${receivedColor(
'received',
)} value must be an @shopify/react-testing Root or Element object`,
`Received ${receivedColor(
'null',
)}.\nThis usually means that your \`.findX\` method failed to find any matching elements.`,
),
);
}
if (
Array.isArray(node) &&
node.length > 1 &&
(node[0] instanceof Root || node[0] instanceof Element)
) {
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),
),
);
}
}
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),
),
);
}
}
function toEqualArrayOf(this: jest.MatcherUtils, received: any[], value: any, length?: number) {
const matcherName = 'toEqualArrayOf';
if (!Array.isArray(received)) {
throw new Error(
matcherErrorMessage(
this.utils.matcherHint(matcherName),
`${this.utils.RECEIVED_COLOR('received')} value must be an array.`,
`Received type: ${typeof received}`,
),
);
}
const receivedPretty = this.utils.printReceived(received);
const elementCheck = received.every((v) => v === value);
const lengthCheck = length === undefined || received.length === length;
if (!lengthCheck) {
return {
pass: false,
message: () => `expected array length to be ${length} but got ${received.length}`,
};