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