Using graphql-tools's addMocksToSchema in a jest test doesn't work with gql from “@apollo/client” #2820
Unanswered
Freddie-Pike
asked this question in
Q&A
Replies: 1 comment 4 replies
-
https://github.com/Freddie-Pike/graphql_tools_workings/blob/main/js/components/providers/ApolloMockingProvider.jsx#L50 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use
graphql-tools
'saddMocksToSchema
function in a jest test with Apollo Client to allow me to test components that query Apollo by returning mock data that I can define for myself. However, the mock data isn't being properly returned when usinguseQuery
.I have a
UserButton
button that I'm trying to write tests for. The component is as follows:Here is my test:
The
ApolloMockingProvider
is based off the following article and the code for it is as follows:The
ApolloMockingProvider
'sglobalMock
's object that's passed intoschemaWithMocks
should return 'John Smith's Button' for theUserButton
'sRenders with first and last name.
test. However, instead I get undefined foruserData
as shown by this error message:Anybody know what the error here is? Reproduction repo is here with the failing test being located here:
Beta Was this translation helpful? Give feedback.
All reactions