javascriptunit-testingmockingjestjsautomocking

How to never mock a particular module with jest?


In particular our codebase uses underscore in many places, and I never want to mock underscore. I know I can jest.unmock('underscore'); in each test that interacts with underscore. Is there a way to unmock underscore globally?


Solution

  • You could add this to package.json.

    "jest": {
        "scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
        "unmockedModulePathPatterns": [
          "enzyme",
          "react",
          "react-addons-test-utils"
        ],
        "verbose": true
      }