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

294
Vistas
Jest: Create a patch for a node module

I need to change a file in a node module which is used by a dependency I'm currently using.

Is there a way I can mock a specific file in node_modules so jest uses it instead of the original one?

I tried creating the same path and file in __mocks__ but it kept using the original file.

Jest Config:

module.exports = {
  testEnvironment:    'node',
  setupFilesAfterEnv: ['./jestSetup.js'],
  testMatch:          ['**/test/**/?(*.)+(spec|test).js'],
  testTimeout:        10000,
  verbose:            true,
  bail:               1,
  clearMocks:         true,
  coverageDirectory:  'coverage',
  resetModules:       true,
  restoreMocks:       true,
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Make sure the __mocks__ directory is adjacent to node_modules (your project root). Jest will automatically use the mock.

Here is a minimum setup that works: https://codesandbox.io/s/stack-overflow-jest-mocks-qejos0?file=/foo.test.js

about 4 years ago · Juan Pablo Isaza Denunciar
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