Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #11148
Closed
Open
Issue created Jun 25, 2021 by Administrator@rootContributor

Allow manual mocks with same name

Created by: thierryxpertsea

Is your proposal related to a problem?

I am currently implementing a bunch of tests with manual mocks. I'd planned to name most of them index.tsx? to mock a component or hook folder exposed through an index.ts file, and I was not able to properly do it since I got this famous message:

jest-haste-map: duplicate manual mock found: index

I tried to use the "modulePathIgnorePatterns" Jest configuration to ignore local manual mocks files, but CRA does not support this option OOTB.

I then changed to use explicit names, such as AccountMenu (which leaded to do a mock call jest.mock('path/to/AccountMenu/AccountMenu'), which is not very convenient). I however reached the limit as I was expecting, since now some components share the same name for different contexts, and I get the warning message again.

Describe the solution you'd like

As a developer, I want to use the manual mock names of my choice, regardless of their uniqueness, so I can easily create standardized mocks in my application, withoutt having any kind of warning in my CI pipeline or in my local environment console.

The best solution would be just not to worry about it anymore as a developer. A default implementation of that configuration in the scripts/utils/createJestConfig.js would be great.

// Something in those lines
+ modulePathIgnorePatterns: [
+     '<rootDir>/src/.*/__mocks__',
+ ],

Describe alternatives you've considered

The whitelisting of the modulePathIgnorePatterns Jest configuration key would also be an acceptable solution, so any developer can manually adjust the configuration

Assignee
Assign to
Time tracking