title: JEST TypeError: Cannot read property 'json' of undefined
body: <p>I'm desperate for help here.  I'm trying to test a function with jest but I'm stuck on one thing.  When I try to mock the fetch request I get this error:</p>
  
  <pre><code>TypeError: Cannot read property 'json' of undefined
  </code></pre>
  
  <p>The function I'm trying to test is this:</p>
  
  <pre><code>const updateUI = async () =&gt;{
      const res = await fetch('/sentiment');
      console.log(res);
      try {
          console.log(res.data)
          const allData = await res.json();
          console.log(allData)
          document.getElementById("polarity").innerHTML = allData.polarity;
          document.getElementById("polarityConfidence").innerHTML = allData.polarity_confidence;
          document.getElementById("subjectivity").innerHTML = allData.polarity;
          document.getElementById("subjectivityConfidence").innerHTML = allData.polarity_confidence;
          return allData;
      }catch(error){
          console.log('error')
      }
  };
  
  export { updateUI }
  </code></pre>
  
  <p>The test I'm trying to run is this:</p>
  
  <pre><code>import "regenerator-runtime/runtime";
  import "core-js/stable";
  import "fetch-mock"
  
  const fetchMock = require('fetch-mock');
  fetchMock.config.sendAsJson = true;  \\I've tried with and without this part and I get the same error
  
  import updateUI from './updateUI';
  import { isIterable } from "core-js";
  
  describe('updateUI', () =&gt; {
      it('can fetch', async () =&gt; {
          fetchMock.get('/sentiment', {polarity: 'polarity', polarity_confidence: 'polarity confidence', subjectivity: 'subjectivity', subjectivity_confidence: 'subjectivity confidence'});
          const res = await updateUI('/sentiment');
          const allData = await res.json();
          expect(allData.polarity).toEqual('polarity');
          expect(allData.polarity_confidence).toEqual('polarity confidence');
          expect(allData.subjectivity).toEqual('subjectivity');
          expect(allData.subjectivity_confidence).toEqual('subjectivity confidence');
  
      })
  })
  </code></pre>
  
  <p>I really have no idea where to go from here.  Why won't it get the json object?  Is it because my updateUI function calls the json object in the try{} part of the function?  If that is the case how do I test it?</p>