title: Testing React component with Jest gives 'Cannot find module' error
body: <p>I am trying to test a React component using Jest.</p>
  
  <p>The component's code is the following.</p>
  
  <pre><code>import React, { PureComponent } from 'react';
  import PropTypes from 'prop-types';
  import { Text } from 'components';
  
  class App extends PureComponent {
  
      static propTypes = {
          name: PropTypes.string.isRequired,
          age: PropTypes.number.isRequired,
          displayed: PropTypes.bool,
      };
  
      static defaultProps = {
          displayed: true
      };
  
      render = () =&gt; {
          if (!this.props.displayed) {
              return null;
          }
          const text = `${ this.props.name } is ${ this.props.age } years old.`
          return (
              &lt;span&gt;
                  &lt;Text
                      text={ text }
                  /&gt;
              &lt;/span&gt;
          );
      }
  }
  
  export default App;
  </code></pre>
  
  <p>The test code is as simple as this:</p>
  
  <pre><code>import React from 'react';
  import { mount } from 'enzyme';
  import App from './../App';
  
  describe('App', () =&gt; {
      let props;
      let mountedApp;
      const app = () =&gt; {
          if (!mountedApp) {
              mountedApp = mount(
                  &lt;App { ...props } /&gt;
              );
          }
          return mountedApp;
      };
  
      beforeEach(() =&gt; {
          props = {
              name: 'John',
              age: 35,
              displayed: undefined
          };
          mountedApp = undefined;
      });
  
      it('always renders a span', () =&gt; {
          const spans = app().find('span');
          expect(spans.length).toBeGreaterThan(0);
      });
  });
  </code></pre>
  
  <p>In my project I am using some Common Components such as Text Component.
  All the paths of the Components are set in an index.js file.</p>
  
  <p>File sample code:</p>
  
  <pre><code>export Button from 'src/Common/Components/Button';
  export Text from 'src/Common/Components/Text';
  export Breadcrumb from 'src/Common/Components/Breadcrumb';
  </code></pre>
  
  <p>This is the Jest configuration I am using in package.json file.</p>
  
  <pre><code>"jest": {
      "setupTestFrameworkScriptFile": "./Common/Components/setupTests.js",
      "moduleFileExtensions": ["js", "jsx", ""],
      "moduleNameMapper": {
        "components(.*)$": "&lt;rootDir&gt;/Common/Static/index.js"
      }
    }
  </code></pre>
  
  <p>Webpack alias config:</p>
  
  <blockquote>
    <p>alias: {
        components: path.resolve(__dirname, 'Common/Static/index.js'), },</p>
  </blockquote>
  
  <p>I am running 'npm test' through terminal and the test fails with the following message:</p>
  
  <pre><code>Test suite failed to run
  
      Cannot find module 'src/Common/Components/Button' from 'index.js'
  
         6 | export Button from 'src/Common/Components/Button';
         7 | export Text from 'src/Common/Components/Text';
      &gt;  8 | export Breadcrumb from 'src/Common/Components/Breadcrumb';
           |                ^
  
        at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:210:17)
        at Object.&lt;anonymous&gt; (Common/Static/index.js:8:16)
  </code></pre>
  
  <p>All the paths are correct and the code runs smoothly when I remove the test.
  I guess that Jest cannot get the paths included in index.js
  Is there any suggestion on how to configure Jest to override this problem?</p>