Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support mock of scoped modules that are symlink with lerna #4760

Closed
jony89 opened this issue Oct 25, 2017 · 9 comments
Closed

support mock of scoped modules that are symlink with lerna #4760

jony89 opened this issue Oct 25, 2017 · 9 comments

Comments

@jony89
Copy link

jony89 commented Oct 25, 2017

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"
  ]
}
@SimenB
Copy link
Member

SimenB commented Oct 25, 2017

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?

@jony89
Copy link
Author

jony89 commented Oct 26, 2017

is there a chance that since it's symlinked lib (using lerna) it affects the mocking somehow? ( I guess not, but worth asking..)

@SimenB
Copy link
Member

SimenB commented Oct 26, 2017

Perhaps. There was a fix merged yesterday for symlinks (#4761), so you can try [email protected] and see if it fixes your problem?

@jony89
Copy link
Author

jony89 commented Oct 26, 2017

@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.

@SimenB
Copy link
Member

SimenB commented Oct 26, 2017

Please provide a repro. Note that this is not a help forum

@jony89
Copy link
Author

jony89 commented Oct 26, 2017

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 SimenB closed this as completed Oct 26, 2017
@jony89 jony89 changed the title support mock of scoped modules support mock of scoped modules that are symlink with lerna Oct 26, 2017
@dtothefp
Copy link

@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

@alistair-hmh
Copy link

I'm getting this error just including any scoped module, regardless of whether I am mocking anything.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants