Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda