Skip to content

Mocking scoped package libraries #4262

@llamamoray

Description

@llamamoray

I've been working on migrating a project which we ejected some time ago back into CRA.

I've come across a problem with the way we are mocking scoped packages. We were using the moduleNameMapper in the jest section of our package.json like this:

package.json

"jest": {
  "moduleNameMapper": {
    "^@org-name/package-one$": "<rootDir>/__mocks__/org-name/package-one/dist/package.js",
    "^@org-name/package-two$": "<rootDir>/__mocks__/org-name/package-two/build/index.js"
  }
}

When I add this to the un-ejected CRA project I get the following error:

These options in your package.json Jest configuration are not currently supported by Create React App:

  • moduleNameMapper

If you wish to override other Jest options, you need to eject from the default setup. You can do so by running npm run eject but remember that this is a one-way operation. You may also file an issue with Create React App to discuss supporting more options out of the box.

Any ideas how I can get these mocks working?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions