Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeEach(() => {
console.error = jest.fn();
renderApp(, {
mocks: [
{
request: {
query: AmILoggedInQuery,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
},
},
result: {
data: null,
errors: [{ message: 'Unauthorized' }],
},
},
],
});
});
it('should call render with `isAuthenticated` set to false', async () => {
it('should render error state', async () => {
const { getByText } = renderUser({
addTypename: true,
mocks: [
{
request: {
query: LoggedInUserQuery,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
},
},
error: new Error('Oops'),
},
],
});
await waitForElement(() => getByText(/Error: Oops/i));
});
});
it('should fetch user and pass data to children function', async () => {
const { getByText } = renderUser({
addTypename: true,
mocks: [
{
request: {
query: LoggedInUserQuery,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
},
},
result: {
data: createGraphqlResponseForUserQuery(),
},
},
],
});
await waitForElement(() => getByText(/John/i));
});
it('should render loading state', async () => {
it('should allow specifying `X-Graphql-Target`-Header', () => {
expect(context.headers).toEqual(
expect.objectContaining({
'X-Graphql-Target': GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
})
);
});
beforeEach(() => {
renderApp(, {
mocks: [
{
request: {
query: AmILoggedInQuery,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
},
},
result: {
data: { loading: false, amILoggedIn: true },
},
},
],
});
});
it('should call render with `isAuthenticated` set to true', async () => {
const ProjectSwitcher = props => {
const intl = useIntl();
const { loading, data } = useQuery(ProjectsQuery, {
onError: reportErrorToSentry,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
},
});
if (loading) return null;
return (
<div data-track-event="click" data-track-component="ProjectSwitch">
</div>
beforeEach(async () => {
await waitFor(
execute(link, {
query,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
projectKey,
},
})
);
});
const FetchUser = props => {
const { loading, data, error } = useQuery(LoggedInUserQuery, {
onError: reportErrorToSentry,
variables: { target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND },
});
return (
<>
{props.children({ isLoading: loading, user: data && data.user, error })}
);
};
FetchUser.displayName = 'FetchUser';
const FetchProject = props => {
const { loading, data, error } = useQuery(ProjectQuery, {
onError: reportErrorToSentry,
variables: {
target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND,
projectKey: props.projectKey,
},
skip: props.skip,
});
return (
<>
{props.children({
isLoading: loading,
error,
project: data && data.project,
})}
);
};
FetchProject.displayName = 'FetchProject';
beforeEach(async () => {
debugLink = new ApolloLink((operation, forward) => {
context = operation.getContext();
return forward(operation);
});
terminatingLinkStub = jest.fn(() => Observable.of({}));
link = ApolloLink.from([headerLink, debugLink, terminatingLinkStub]);
await waitFor(
execute(link, {
query,
variables: { target: GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND },
})
);
});