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

unmockedModulePathPatterns not working? #551

Closed
Nic128 opened this issue Oct 14, 2015 · 10 comments
Closed

unmockedModulePathPatterns not working? #551

Nic128 opened this issue Oct 14, 2015 · 10 comments

Comments

@Nic128
Copy link

Nic128 commented Oct 14, 2015

I need help figuring something out with unmockedModulePathPatterns.

From my package.json,

  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
    "testFileExtensions": ["es6", "js", "jsx"],
    "moduleFileExtensions": ["js", "jsx", "json", "es6"],
    "verbose": true,
    "testPathIgnorePatterns": [
      "<rootDir>/node_modules"
    ],
    "modulePathIgnorePatterns": [
      "<rootDir>/node_modules"
    ],
    "unmockedModulePathPatterns": [  "<rootDir>/node_modules/react" ]
  },

From the docs: An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them. Should I be using a different syntax inside my array. (Maybe like /react/) I've tried a bunch a combination, wasn't working.

If I don't include in my test jest.dontMock('react');, the mock always stays on. Is it normal? Using 0.5.10.

@adriantoine
Copy link

I have issues with unmockedModulePathPatterns too, so the syntax: "<rootDir>/node_modules/react" doesn't work for me, but it works if I only put "react" without the directory like that:

"unmockedModulePathPatterns": [
  "react",
  "react-dom",
  "react-addons-test-utils"
]

edit see #100

@cpojer
Copy link
Member

cpojer commented Oct 15, 2015

yes, node_modules are unmocked just by their name.

@Nic128
Copy link
Author

Nic128 commented Oct 16, 2015

I haven't been able to make any combination of syntax work. The only thing that works is jest.dontMock('react') or jest.autoMockOff().

Form Select component  it encountered a declaration exception
  - TypeError: /home/nmartel/repos/UI-UNIT/node_modules/react/react.js: /home/nmartel/repos/UI-UNIT/node_modules/react/lib/React.js: /home/nmartel/repos/UI-UNIT/node_modules/react/lib/ReactDOM.js: /home/nmartel/repos/UI-UNIT/node_modules/react/lib/ReactDefaultInjection.js: /home/nmartel/repos/UI-UNIT/node_modules/react/lib/BeforeInputEventPlugin.js: Cannot read property 'topCompositionEnd' of undefined

@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

Are you using npm3?

@Nic128
Copy link
Author

Nic128 commented Oct 16, 2015

Yes.

@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

:(

#554

@cpojer cpojer closed this as completed Oct 16, 2015
@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

We need to fix this in jest!

@Nic128
Copy link
Author

Nic128 commented Oct 16, 2015

Well, at least I found out with that other thread that 'fbjs' needed to be unmocked too. Wasn't clear.

@cpojer
Copy link
Member

cpojer commented Oct 16, 2015

Yep! We'll try to figure out a proper solution.

@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 14, 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

3 participants