Using createMockClient
for testing non react code?
#317
Labels
🧪 testing
Feature requests related to testing
createMockClient
for testing non react code?
#317
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
The text was updated successfully, but these errors were encountered: