title: jest.advanceTimersByTime doesn't work when I try to test my retry util function
body: <p>I have a retry util function I wanted to test for. It looks like this</p>
  <pre><code>export const sleep = (t: number) =&gt; new Promise((r) =&gt; setTimeout(r, t));
  
  type RetryFn = (
    fn: Function,
    config: {
      retryIntervel: number;
      retryTimeout: number;
      predicate: Function;
      onRetrySuccess?: Function;
      onRetryFail?: Function;
    }
  ) =&gt; Promise&lt;any&gt;;
  
  export const retry: RetryFn = async (
    fn,
    { predicate, onRetrySuccess, onRetryFail, retryIntervel, retryTimeout }
  ) =&gt; {
    const startTime = Date.now();
    let retryCount = 0;
    while (Date.now() - startTime &lt; retryTimeout) {
      try {
        const ret = await fn();
        if (predicate(ret)) {
          if (retryCount &gt; 0) onRetrySuccess &amp;&amp; onRetrySuccess();
          return ret;
        } else {
          throw new Error();
        }
      } catch {
        retryCount++;
      }
      await sleep(retryIntervel);
    }
    if (onRetryFail) onRetryFail();
  };
  
  </code></pre>
  <p>what it does is retry the function for a period of time at a given interval.</p>
  <p>I thought I could use <code>jest.advanceTimersByTime</code> to advance the timer to test how many times the retry happens.</p>
  <pre class="lang-js prettyprint-override"><code>import { retry } from &quot;./index&quot;;
  
  const value = Symbol(&quot;test&quot;);
  
  function mockFnFactory(numFailure: number, fn: Function) {
    let numCalls = 0;
    return function () {
      fn();
      numCalls++;
      if (numCalls &lt;= numFailure) {
        console.log(&quot;numCalls &lt;= numFailure&quot;);
  
        return Promise.resolve({ payload: null });
      } else {
        console.log(&quot;numCalls =&gt; numFailure&quot;);
  
        return Promise.resolve({
          payload: value
        });
      }
    };
  }
  
  describe(&quot;retry function&quot;, () =&gt; {
    beforeEach(() =&gt; {
      jest.useFakeTimers();
    });
    it(&quot;retrys function on 1st attempt, and succeed thereafter&quot;, async () =&gt; {
      const fn = jest.fn();
      const onRetrySuccessFn = jest.fn();
      const mockFn = mockFnFactory(3, fn);
      retry(mockFn, {
        predicate: (res: any) =&gt; res.payload === value,
        onRetrySuccess: onRetrySuccessFn,
        retryIntervel: 1000,
        retryTimeout: 5 * 60 * 1000
      });
      jest.advanceTimersByTime(1000);
      expect(fn).toHaveBeenCalledTimes(1);
      expect(onRetrySuccessFn).not.toHaveBeenCalled();
      jest.advanceTimersByTime(1000);
      expect(fn).toHaveBeenCalledTimes(2); //  fail
      expect(onRetrySuccessFn).not.toHaveBeenCalled();
      jest.advanceTimersByTime(2000);
      expect(fn).toHaveBeenCalledTimes(3);//  fail
      expect(onRetrySuccessFn).toHaveBeenCalledTimes(1);
    });
  });
  
  </code></pre>
  <p>but it seems like no matter <strong>how much I advanced the timer, the function only gets invoked once.</strong></p>
  <p>You can find the code on codesandbox at <a href="https://codesandbox.io/s/lucid-knuth-e810e?file=/src/index.test.ts" rel="noreferrer">https://codesandbox.io/s/lucid-knuth-e810e?file=/src/index.test.ts</a></p>
  <p>However, there is a known <a href="https://github.com/codesandbox/codesandbox-client/issues/513" rel="noreferrer">issue</a> with codesandbox where it keeps throwing this error <code>TypeError: jest.advanceTimersByTime is not a function</code> . This error doesn't appear locally.</p>