title: Jest - mocking a default export module
body: <p>I have a module which export a default.</p>
  <pre><code>import { createNamespace } from 'node-request-context';
  const namespace = createNamespace('request-metadata');
  
  export default namespace;
  </code></pre>
  <p>This module is required in a different file, like so:</p>
  <pre><code>....
  import loggingContext from '../utils/loggingContext';
  ....
  
  export function myFunc(data) {
    return new Promise((resolve, reject) =&gt; {
      ......
      loggingContext.run(() =&gt; {
        loggingContext.set('metadata', {
           userId
        });
      });
      const userEmail = loggingContext.get('metadata', 'email');
    });
  }
  
  ...
  </code></pre>
  <p>So we can see that the <code>loggingContext</code> module exports <code>run</code>, <code>get</code> and <code>set</code> methods.
  I want to mock it and those methods in my unit tests but I keep getting an error:</p>
  <p><code>TypeError: Cannot read property 'metadata' of undefined</code></p>
  <p>This is my latest attempt to mock it</p>
  <pre><code>import loggingContext from '../../src/utils/loggingContext';
  
  jest.mock('../../src/utils/loggingContext', () =&gt; {
    return {
      __esModule: true,
      default: {
        run: jest.fn(),
        get: jest.fn(),
        set: jest.fn(),
      }
     };
  });
  </code></pre>
  <p>Please advise how can I mock it properly?</p>