Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

181
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda