title: @testing-library/react-hooks calls setTimeout two times
body: <p>Here is my custom React-hook.</p>
  <pre class="lang-js prettyprint-override"><code>import { useEffect, useRef } from 'react'
  
  function useInterval({ callback, interval, delay }) {
    const savedTimerId = useRef&lt;NodeJS.Timeout&gt;()
  
    useEffect(() =&gt; {
      const loop = () =&gt; {
        const res = callback()
        const nextIteration = () =&gt; {
          savedTimerId.current = setTimeout(loop, interval)
        }
        if (res instanceof Promise) {
          res.then(nextIteration)
        } else {
          nextIteration()
        }
      }
      let delayedTimerId: NodeJS.Timeout
      if (!delay) {
        loop()
      } else {
        delayedTimerId = setTimeout(loop, delay)
      }
      return () =&gt; {
        // @ts-ignore
        clearTimeout(savedTimerId.current)
        if (delayedTimerId) {
          clearTimeout(delayedTimerId)
        }
      }
    }, [callback, interval, delay])
  }
  
  export { useInterval }
  </code></pre>
  <p>And here is the unit test</p>
  <pre class="lang-js prettyprint-override"><code>import { renderHook } from '@testing-library/react-hooks'
  import { useInterval } from '../useInterval'
  
  describe(&quot;Test scenarios for 'useInterval' hook&quot;, () =&gt; {
    jest.useFakeTimers()
  
    it(&quot;Should call 'callback' once&quot;, () =&gt; {
      const callback = jest.fn()
      const interval = 10000
      const params = { callback, interval }
      renderHook(() =&gt; useInterval(params))
      expect(setTimeout).toHaveBeenCalledTimes(1)
      expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), interval)
    })
  })
  </code></pre>
  <p>But that's the output</p>
  <pre><code>Error: expect(jest.fn()).toHaveBeenCalledTimes(expected)
  
  Expected number of calls: 1
  Received number of calls: 2
  </code></pre>
  <p>I debugged this snippet. I found that before <code>useInterval</code> invocation something has already triggered <code>setTimeout</code>.
  <a href="https://i.stack.imgur.com/1CMnr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1CMnr.png" alt="debug result" /></a></p>
  <p>Seems like <code>setTimeout</code> has been called internally. What am doing wrong? Any ideas?</p>