duplicated file name - index.js - jest-haste-map

Viewed 372

I am getting this error with Jest - the file path is different which is making me wonder why this is complaining? I think i am being told that index.js is a duplicated name even though the mocks are on different paths - surely not? I am using mocks from both these in a test file - am i unable to use index files with jest?!

jest-haste-map: duplicate manual mock found: index
  The following files share their name; please delete one of them:
    * <rootDir>/dist/Actions/SendDistributions/__mocks__/index.js
    * <rootDir>/dist/Actions/SendQualifications/__mocks__/index.js

jest-haste-map: duplicate manual mock found: index
  The following files share their name; please delete one of them:
    * <rootDir>/dist/Actions/SendQualifications/__mocks__/index.js
    * <rootDir>/dist/Actions/SendLeads/__mocks__/index.js

1 Answers

To remove the warning, you need to add the following to your jest config - jest.config.js or package.json etc.

jest.config.js

module.exports = {
  ...,
  modulePathIgnorePatterns: ["<rootDir>/.*/__mocks__"]
};

OR

package.json

"jest": {
    "modulePathIgnorePatterns": [
        "<rootDir>/.*/__mocks__"
    ]
}

You can then continue to use mocks structured the way you have shown.

Related