For a project using Apollo GraphQL, I'm referencing to a client variable to execute a mutation. This is for refreshing tokens in a link, therefor I can't use any react hooks.
For testing, I created a mockClient with the same data as I would give into my MockedProvider;
const mockClient = createMockClient(data, REFRESH_MUTATION))
To replace the actual Apollo client with this, I simply use a require which works;
require('modules/ApolloProvider').client = createMockClient(
data,
REFRESH_MUTATION
)
Notice the client is a named export and not a default export. I want to do the same thing with Jest's mock functionality, and tried this snippet at the beginning of my test;
jest.doMock('modules/ApolloProvider', () => {
return {
client: jest.fn(() => mockClient),
}
})
I also the __esModule: true option, but had no luck. How comes the test passes on the first snippet, but not when using Jest?
Also, I tried it without the jest.fn() wrap.