Do you want to request a feature or report a bug?
bug, while using ES6 modules and babelrc.
What is the current behavior?
my scoped package in node_modules is not mocked using :
jest.mock('@my-scope/module-name', () => ({
example: jest.fn(),
}));
What is the expected behavior?
the module will be mocked
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
node - v8.4.0
npm - 5.2.0
jest - 21.2.0
OS - macOS
{
"transform": {
"^.+\\.js$": "babel-jest"
},
"collectCoverageFrom": ["src/**/*.{js}"],
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js",
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom"
]
}
Mocking scoped deps definitely works, I do it quite extensively in projects at work.
Do you have a full repro instead of an example snippet?
is there a chance that since it's symlinked lib (using lerna) it affects the mocking somehow? ( I guess not, but worth asking..)
Perhaps. There was a fix merged yesterday for symlinks (#4761), so you can try [email protected] and see if it fixes your problem?
@SimenB I tried, though it is still using the original module instead of the mocked one.
Also that issue seems irrelevant to mine.
My problem is that the dep module is written with ES6 and not transpiled using babel, since it's under node_modules. so mocking it seems like a correct solution.
At first I thought to transpile it, thought I could not configure babel nor pointing jest to webpack config in order to transpile this specific module under node_modules. yet again, mocking it seems like a better solution for me.
Please provide a repro. Note that this is not a help forum
I Could not mock modules which are symlinked (using lerna) + scoped modules with jest.mock . I ended up using __mocks__ folder to mock the module for now.
@SimenB same here. When using Lerna with symlinked packages I must use the __mocks__ directory as described here https://facebook.github.io/jest/docs/en/manual-mocks.html#mocking-node-modules
I'm getting this error just including any scoped module, regardless of whether I am mocking anything.
Most helpful comment
I Could not mock modules which are symlinked (using
lerna) + scoped modules with jest.mock . I ended up using__mocks__folder to mock the module for now.