jest-haste-map: duplicate manual mock found when the duplicate is in the build folder
See original GitHub issueI’m getting a warning from Jest for each manual mock I have, because it appears to be looking in the src directory and in the dist
directory where I output my build.
I get the
jest-haste-map: duplicate manual mock found:
Module name: index
Duplicate Mock path: /Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts
Please delete one of the following two files:
/Users/paul.cowan/projects/ds/payments/api/dist/__mocks__/index.js
/Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts
I’ve tried mucking around with the exclude key in my tsconfig.json, but I can’t find a glob pattern that matches all mocks folders.
I.e. "exclude":["**/__mocks__/*"]
but it still happens
rootDir: process.cwd(),
coverageDirectory: '<rootDir>/.coverage',
collectCoverageFrom: [
'src/**/*.{js,jsx,ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.test.*',
'!src/test/**/*.*',
'!src/features/**/*.*'
],
setupFiles: ['@ds/common/scripts/tests/setupTests.js', '@ds/common/config/polyfills.js'],
testMatch: [
'<rootDir>/src/**/__tests__/**/*.ts?(x)',
'<rootDir>/src/**/?(*.)(spec|test).ts?(x)',
'<rootDir>/src/**/*.feature'
],
testEnvironment: 'node',
testURL: 'http://localhost',
transform: {
'^.+\\.(ts|tsx)$': '<rootDir>/../../node_modules/ts-jest/preprocessor.js',
'^.+\\.feature$': 'gherkin-jest',
'^.+\\.css$': '@ds/common/jest/cssTransform.js',
'^.+\\.csv$': '@ds/common/jest/csvTransform.js',
'^(?!.*\\.(js|jsx|css|json)$)': '@ds/common/jest/fileTransform.js'
},
transformIgnorePatterns: ['[/\\\\](node_modules)[/\\\\].+\\.(js|jsx)$'],
moduleNameMapper: {
'^react-native$': 'react-native-web'
},
moduleFileExtensions: ['web.js', 'js', 'json', 'web.jsx', 'jsx', 'ts', 'tsx', 'feature', 'csv']```
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14
Top Results From Across the Web
How to handle duplicated manual mock found in the project
Put "<rootDir>/build" inside modulePathIgnorePatterns , the rootDir is not a placeholder but a special token Jest can recognise, ...
Read more >Manual Mocks · Jest
Here's a contrived example where we have a module that provides a summary of all the files in a given directory. // FileSummarizer.js...
Read more >How to handle duplicated manual mock found in the project ...
jest -haste-map: duplicate manual mock found: Module name: fileMock ... Add the build folder into modulePathIgnorePatterns inside your package.json file.
Read more >jest-haste-map: duplicate manual mock found: next/config
jest will complain if we have more than one manual mock on the same module, even when they are placed in a different...
Read more >[bug] duplicate manual mock found in separate directories
... I'm given the duplicate manual mock found error from jest-haste-map . If, however, I try to create src/app/modules/__mocks__/{module1.js ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In jest.config.js add this.
@htbkoo for me the solution was quite easy as I’m using typescript, I just added the
__mocks__
folder to the exclude list:"exclude": ["**/__mocks__/*", "../../node_modules", "build", "src/**/*.test.ts", "src/**/*.test.tsx"]