title: Jest mocking default exports - require vs import
body: <p>I have seen questions referring to the mocking of default exports with jest around here, but I don't think this has already been asked:</p>
  
  <p>When mocking the default export of a dependency of a module that is being tested, the tests suite fails to run if the module imports the dependency with the ES6 import statement, stating <code>TypeError: (0 , _dependency.default) is not a function</code> It succeeds, however, if the module uses a <code>require().default</code> call instead.</p>
  
  <p>In my understanding, <code>import module from location</code> directly translates to <code>const module = require(location).default</code>, so I am very confused why this is happening. I'd rather keep my code style consistent and not use the <code>require</code> call in the original module. </p>
  
  <p>Is there a way to do it?</p>
  
  <p>Test file with mock:</p>
  
  <pre><code>import './modules.js';
  import dependency from './dependency';
  
  jest.mock('./dependency', () =&gt; {
     return {
        default: jest.fn()
     };
  });
  
  // This is what I would eventually like to call
  it('calls the mocked function', () =&gt; {
     expect(dependency).toHaveBeenCalled();
  });
  </code></pre>
  
  <p>Dependency.js</p>
  
  <pre><code>export default () =&gt; console.log('do something');
  </code></pre>
  
  <p>module.js (not working)</p>
  
  <pre><code>import dependency from './dependency.js';
  dependency();
  </code></pre>
  
  <p>module.js (working)</p>
  
  <pre><code>const dependency = require('./dependency.js').default;
  dependency();
  </code></pre>