title: How to verify that node-fetch is called in typescript unit test?
body: <p>Hi I've a module that export some methods and I would like to test them with some unit tests. My project is based on typescript ^3.9.7 and it is installed jest ^26.1.0 and ts-jest ^26.2.0</p>
  <p>One of these methods import node-fetch ^2.6.0 to be able to use window.fetch in node environment.</p>
  <pre><code>import fetch from 'node-fetch'
  
  export const fetchResponseFromRemoteFile = (
    remoteFileUrl: string
  ): Promise&lt;Response&gt; =&gt;
    fetch(remoteFileUrl)
      .then(res =&gt; {
        return res.status === 200
          ? res
          : new Error(`failed to retrieve ${remoteFileUrl}`)
      })
      .catch(e =&gt; e)
  </code></pre>
  <p>In one of my test I wanna check that <em>fetchResponseFromRemoteFile</em> calls <em>fetch</em></p>
  <p><strong>approach 1</strong></p>
  <pre><code>import { mocked } from 'ts-jest/utils'
  import fetch from 'node-fetch'
  
  jest.mock('node-fetch')
  
  it('fetches', async () =&gt; {  
    const expectedResponse = { a: 1 }
    mocked(fetch).mockImplementation( () =&gt; &lt;any&gt;expectedResponse)
    ...
  })
  
  
  // mocked(fetch).mockImplementation( () =&gt; &lt;any&gt;expectedResponse)
  
  TypeError: (0 , _utils2.mocked)(...).mockImplementation is not a function
  
  </code></pre>
  <p><strong>approach 2</strong></p>
  <pre><code>it('fetches', async () =&gt; {
    const expectedResponse = { a: 1 }
    ;(fetch as jest.Mock).mockReturnValue(Promise.resolve(new Response(expectedResponse)))
    const remoteFile = await utils.fetchResponseFromRemoteFile(mockUrl)
    expect(fetch).toHaveBeenCalledTimes(1)
    expect(remoteFile.status).toEqual(200);
    expect(remoteFile.body).toEqual(expectedResponse);
    ...
  })
  
  
  // ;(fetch as jest.Mock).mockReturnValue(Promise.resolve(new Response(expectedResponse)))
  
  ReferenceError: Response is not defined
  </code></pre>
  <p><strong>approach 3</strong></p>
  <pre><code>import fetch from 'node-fetch'
  
  jest.mock('node-fetch', () =&gt; jest.fn())
  
  it('fetches', async () =&gt; {
    const expectedResponse = { body: { a: 1 } }
    const response = Promise.resolve(expectedResponse)
    fetch.mockImplementation(()=&gt; response)
    ...
  })
  
  
  // fetch.mockImplementation(()=&gt; response)
  
  TypeError: _nodeFetch.default.mockImplementation is not a function
  </code></pre>
  <p>Ideas on what is going on here?
  Thanks in advance</p>