title: How do I stub a module with Jest and Proxyquire?
body: <p>I want to force <code>node-fetch</code> to be a stub and I'm having a bit of trouble 
  getting it to work. Code: </p>
  
  <pre><code>const fetchMock = jest.fn();
  
  const {
    getArticle 
  } = require('../../sfpublish/api');
  console.log('loaded api')
  const A = global.proxyquire('../../sfpublish/api', {
    'node-fetch': fetchMock
  });
  </code></pre>
  
  <p><code>setup.js</code>: </p>
  
  <pre><code>global.proxyquire = require('proxyquire');
  </code></pre>
  
  <p><code>package.json</code>: </p>
  
  <pre><code>"jest": {
      "automock": false,
      "globalSetup": "./test/__config.js",
      "setupFiles": [
        "./test/__setup.js"
      ]
    },
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code>FAIL  test/sfpublish/api.test.js
    ● Test suite failed to run
  
      Cannot find module '../../sfpublish/api'
  
        23 | } = require('../../sfpublish/api');
        24 | console.log('loaded api')
      &gt; 25 | const A = global.proxyquire('../../sfpublish/api', {
           |                  ^
        26 |   'node-fetch': fetchMock
        27 | });
  </code></pre>
  
  <p>How can it be failing to load the module that I just loaded 2 lines previous? Is <code>proxyquire</code> not the right module to use here?</p>
  
  <p>I've gotten <code>node-fetch</code> to be a mock in my test but when I run the function in the module (which has <code>const fetch = require('node-fetch');</code> at the top) it's going to the real module instead of the fake. I've tried using fetch mocking libs like <code>fetch-mock</code> to no avail. </p>