Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing getInitialProps when using ctx.apolloClient #144

Open
alexjfno1 opened this issue Jul 17, 2020 · 0 comments
Open

Testing getInitialProps when using ctx.apolloClient #144

alexjfno1 opened this issue Jul 17, 2020 · 0 comments

Comments

@alexjfno1
Copy link

I have a page component that is using getInitialProps to fetch data using Apollo via the ctx.apolloClient.

Page.getInitialProps = async (ctx: ApolloPageContext) => {
  const response = await ctx.apolloClient.query({ query: QUERY, variables: { productId: '123' } });
  return { product: response.data.product };
};

When testing a normal component I can use the MockedProvider from @apollo/react-testing to stub about the queries. However I'm a bit lost to how I would test the getInitialProps function.

I could just mock out the ctx.apolloClient.query function to return the expected data but this won't provide much value. Is there a way to mock out the apollo client in the NextJS context similar to the way MockedProvider works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant