title: How properly test setTimeout after Promise resolve
body: <p>How to propertly test this function.</p>
  
  <ol>
  <li>Set timeout</li>
  <li>Callback after timeout</li>
  <li>And recursive call</li>
  </ol>
  
  <pre class="lang-js prettyprint-override"><code>export function initScheduler(timeout: number, callback: () =&gt; Promise&lt;void&gt;): void {
    setTimeout(() =&gt; {
      callback().then(() =&gt; {
        initScheduler(timeout, callback);
      });
    }, timeout);
  }
  </code></pre>
  
  <p>I tried something like </p>
  
  <pre class="lang-js prettyprint-override"><code>describe('initScheduler', () =&gt; {
    it('should call on schedule', () =&gt; {
      jest.useFakeTimers();
  
      const timeout: number = 60000;
      const callback: jest.Mock = jest.fn().mockResolvedValue(undefined);
  
      initScheduler(timeout, callback);
  
      expect(setTimeout).toHaveBeenCalledTimes(1);
      expect(setTimeout).toHaveBeenLastCalledWith(expect.any(Function), timeout);
      expect(callback).not.toBeCalled();
  
      jest.advanceTimersByTime(timeout);
  
      expect(callback).toBeCalled();
      expect(setTimeout).toHaveBeenCalledTimes(2);
    });
  });
  </code></pre>
  
  <p>But last expectation returns 1</p>