rewire icon indicating copy to clipboard operation
rewire copied to clipboard

Rewire seems to doesn't work with Jest config "moduleNameMapper"

Open victorchapado opened this issue 5 years ago • 2 comments

Hi, I have the below configuration for the Jest test framework:

module.exports = Object.assign({}, jestBaseConfig, {
  moduleNameMapper: {
    moduleB: '<rootDir>/node_modules/moduleB/index.js',
  },
});

I'm trying to test one module (ModuleA) that requires this one (ModuleB). ModuleA |__ requires --> ModuleB

When I use require for ModuleA, ModuleB is resolved correctly but, if I try to rewire ModuleA, ModuleB is not found. In particular, the message is:

Cannot find module 'ModuleB'

rewire: "version": "4.0.1" jest: "version": "24.9.0"

Hoping that the explanation is pretty clear. Thanks!

victorchapado avatar Jan 08 '20 17:01 victorchapado

Same issue here, with versions: rewire: "5.0.0" jest: "26.3.0"

woodardj avatar Aug 11 '20 22:08 woodardj

I also get the same issue

ppopth avatar Aug 23 '21 07:08 ppopth