Naming conventions for manual mocks in Jest test runner
<p>This is my project folder structure,</p>

<p><strong>Folder Structure</strong></p>

<pre><code>app
  - api
    - api1
      __mocks__
          index.js
      - index.js
    - api2
      __mocks__
          index.js
      - index.js
  - components
    -component1
       - index.js
       __tests__
           component1.test.js
</code></pre>

<p>Right now I have <code>component1</code> which internally uses <code>api1</code> to do some requests.
There are two issues that I am facing with the current folder structure and mocking the api modules.</p>

<ol>
<li>How should I be naming the files under <code>api/__mocks__</code>? should it be <code>index.js</code> (the same of as <code>index.js</code> under <code>api1</code>) or should it be <code>api1.mocks.js</code>? Is there a naming convention that is required for jest?</li>
<li>Right now with the current structure jest is throwing me the following error,</li>
</ol>

<p><strong>Jest Error:</strong></p>

<blockquote>
  <p>jest-haste-map: duplicate manual mock found:   Module name: index</p>
</blockquote>

<p>Is there a documentation somewhere that talks about naming mocks?</p>

<p>This is my jest configuration from package.json,</p>

<p><strong>package.json:</strong></p>

<pre><code>"jest": {
    "testEnvironment": "jsdom",
    "testPathDirs": [
      "&lt;app-path&gt;"
    ],
    "modulePaths": [
      "&lt;app-path&gt;"
    ],
    "enableAutomock": true,
    "moduleNameMapper": {
      "^components": "&lt;rootDir&gt;/components",
      "^services": "&lt;rootDir&gt;/services",
      "^api": "&lt;rootDir&gt;/api",
      "^.+\\.less$": "&lt;rootDir&gt;/__mocks__/styleMocks.js"
    }
  }
</code></pre>

<p><strong>Simple unit test:</strong></p>

<pre><code>import React from 'react';
import {mount} from 'enzyme';
import Component from 'components/Component1';

jest.mock('api/api1');

describe('Component1 Unit tests', () =&gt; {
  it('Should render', () =&gt; {
    const c1 = mount(
      &lt;Component1 /&gt;
     );
     expect(...);
  });
});
</code></pre>