title: jest.spyOn mock return value not returning value
body: <p>The code I'm trying to test:</p>
  <pre><code>const utils = require('../utils/utils');
  
          let imageBuffer;
          try {
              imageBuffer = await utils.retrieveImageFromURI(params)
              console.log(imageBuffer) // comes back as undefined when I mock the utils.retreieveImageFromURI
              if (!imageBuffer || imageBuffer.length &lt; 1024) {
                  throw new Error(`Retrieve from uri (${params.camera.ingest.uri}) was less than 1kb in size - indicating an error`)
              }
              console.log(`${params.camera.camId} - Successful Ingestion from URI`);
          } catch (err) {
              reject({ 'Task': `Attempting to pull image from camera (${params.camera.camId}) at ${params.camera.ingest.uri}`, 'Error': err.message, 'Stack': err.stack })
              return;
          }
  </code></pre>
  <p>Specifically, I'm trying to mock the utils.retrieveImageFromURI function - which has API calls and other things in it.</p>
  <p>When I try to mock the function using spyOn I am trying it like so:</p>
  <pre><code>describe(&quot;FUNCTION: ingestAndSave&quot;, () =&gt; {
      let fakeImageBuffer = Array(1200).fill('a').join('b'); // just get a long string
      console.log(fakeImageBuffer.length) //2399
      let retrieveImageFromURISpy
      beforeAll(() =&gt; {
          retrieveImageFromURISpy = jest.spyOn(utils, 'retrieveImageFromURI').mockReturnValue(fakeImageBuffer) 
      })
  
      test(&quot;Will call retrieveImageFromURI&quot;, async () =&gt; {
          await ingest.ingestAndSave({camera:TEST_CONSTANTS.validCameraObject, sourceQueueURL:&quot;httpexamplecom&quot;, receiptHandle: &quot;1234abcd&quot;})
          expect(retrieveImageFromURISpy).toHaveBeenCalledTimes(1)
      })
  
      afterEach(() =&gt; {
          jest.resetAllMocks()
      })
      afterAll(() =&gt; {
          jest.restoreAllMocks()
      })
  })
  </code></pre>
  <p>When I do this, I get a console log that imageBuffer (which is supposed to be the return of the mocked function) is <code>undefined</code> and that, in turn, triggers the thrown Error that <code>&quot;Retrieve from uri ....&quot;</code> ... which causes my test to fail.  I know I could wrap the test call in a try/catch but the very next test will be a &quot;does not throw error&quot; test... so this needs to be solved.</p>
  <p>It's not clear to me why the mockReturnValue isn't getting returned.</p>
  <p><strong>Other steps:</strong></p>
  <p>I've gone to the REAL <code>retrieveImageFromURI</code> function and added a console log - it is not running.</p>
  <p>I've changed mockReturnValue to mockImplementation like so:</p>
  <pre><code>retrieveImageFromURISpy = jest.spyOn(utils, 'retrieveImageFromURI').mockImplementation(() =&gt; {
              console.log(&quot;Here&quot;)
              return fakeImageBuffer
          }) 
  </code></pre>
  <p>And it does NOT console log 'here'.  I'm unsure why not.</p>
  <p>I have also tried to return it as a resolved Promise, like so:</p>
  <pre><code>retrieveImageFromURISpy = jest.spyOn(utils, 'retrieveImageFromURI').mockImplementation(() =&gt; {
      console.log(&quot;Here&quot;)
      return Promise.resolve(fakeImageBuffer)
  }) 
  </code></pre>
  <p>Note, this also doesn't console log.</p>
  <p>I've also tried to return the promise directly with a mockReturnValue:</p>
  <pre><code>`retrieveImageFromURISpy = jest.spyOn(utils, 'retrieveImageFromURI').mockReturnValue(Promise.resolve(fakeImageBuffer)`) 
  </code></pre>