Skip to content

Commit

Permalink
feat(timer): add asynchronous callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumeduboc committed Nov 9, 2022
1 parent afb86cc commit 045d8c1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/core/test/timers.test.ts
Expand Up @@ -440,6 +440,30 @@ describe('FakeTimers', () => {
await timers.runAllAsyncTimers()
expect(fn).toHaveBeenCalledTimes(1)
})

it('all callbacks are called when setTimeout calls asynchronous method', async () => {
const global = { Date: FakeDate, clearTimeout, process, setTimeout, Promise }
const timers = new FakeTimers({ global })
timers.useFakeTimers()

const runOrder = []
const mock2 = vi.fn(async () => {
runOrder.push('mock2')
return global.Promise.resolve(true)
})
const mock1 = vi.fn(async () => {
await mock2()
runOrder.push('mock1')
})

global.setTimeout(mock1, 100)
await timers.runAllAsyncTimers()

expect(runOrder).toEqual([
'mock2',
'mock1',
])
})
})

describe('advanceTimersByTime', () => {
Expand Down

0 comments on commit 045d8c1

Please sign in to comment.