title: How to make Jest test client-side scripts?
body: <p>I've got some client-side code that I'd like to test with Jest. Let's narrow it down to this reproducible bit:</p>
  
  <pre><code>// fetch-example.js
  const fetchExample = () =&gt; fetch('http://example.org/');
  module.exports = fetchExample
  </code></pre>
  
  <p>Since Jest runs tests via Node and Node doesn't support <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API" rel="nofollow noreferrer">fetch</a>, the following test script</p>
  
  <pre><code>// fetch-example.test.js
  const fetchExample = require('./fetch-example')
  test('fetch resolves to something', () =&gt; {
      expect.assertions(1);
      return fetchExample().then(() =&gt; expect(true).toBe(true));
  });
  </code></pre>
  
  <p>fails with <code>ReferenceError: fetch is not defined</code>. No surprises, but... <code>fetchExample</code> works fine in a browser and I'd like Jest to take this into account and mark the test as passed.</p>
  
  <p>Is there any way to make this work? Is there any parameter I can pass to Jest to include browser functions like <code>fetch</code>?</p>
  
  <p>NB: Jest's <a href="https://jestjs.io/docs/en/configuration.html#browser-boolean" rel="nofollow noreferrer">browser</a> configuration entry does not make it work.</p>