Jest: Timer and Promise don’t work well. (setTimeout and async function)
Yes, you’re on the right track. What happens await simpleTimer(callback) will wait for the Promise returned by simpleTimer() to resolve so callback() gets called the first time and setTimeout() also gets called. jest.useFakeTimers() replaced setTimeout() with a mock so the mock records that it was called with [ () => { simpleTimer(callback) }, 1000 ]. … Read more