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

291
Views
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 answers
Answer question

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 Report
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!