Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Difference between jest's doMock and require

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!