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

Using createMockClient for testing non react code? #317

Open
seisenreich opened this issue Oct 28, 2021 · 0 comments
Open

Using createMockClient for testing non react code? #317

seisenreich opened this issue Oct 28, 2021 · 0 comments
Labels
🧪 testing Feature requests related to testing

Comments

@seisenreich
Copy link

I have a mixed application that uses Apollo for both React and non-react code.
However, I can’t find documentation or code examples around testing non-react code with the apollo client,not using MockedProvider. I did, however, notice that apollo exports a mock client from the testing directory.

import { createMockClient } from '@apollo/client/testing';

I haven’t found any documentation about this API and am wondering if it’s intended to be used publicly and, if not, what the supported approach is for this.

The reason I need this is simple: When using Next.js’ SSR and/or SSG features data fetching and actual data rendering are split into separate functions.
So the fetching code is not using React, but Node.js to fetch data.
Therefore I use apolloClient.query to fetch the data I need.

When trying to wrap a react component around that fetching code in a test an wrap MockedProvider around that the apolloClient’s query method always returns undefined for mocked queries - so it seems this only works for the useQuery hook?

Do you have any idea how to mock the client in non-react code?
Thank you for your support in advance. If you need any further information from me feel free to ask.

Probable soutions

In case apolloClient should support mocking the client for testing non react code: please document it.

If not: please add this functionality.
I don't want to use multiple libraries for fetching gql queries for server side and client side and could imagine I'm not the only user who has this use case.

Regards,
Horstcredible

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

No branches or pull requests

3 participants