Skip to content

Commit

Permalink
chore: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Dec 5, 2024
1 parent fc9ecc5 commit 54a59f9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/node/src/__tests__/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('XKeysWatcher', () => {
{
HIDMock.mockSetDevices([])

await sleep(POLL_INTERVAL)
await sleepTicks(POLL_INTERVAL)
expect(onDisconnected).toHaveBeenCalledTimes(1)
}
} catch (e) {
Expand All @@ -70,6 +70,13 @@ describe('XKeysWatcher', () => {
expect(onError).toHaveBeenCalledTimes(0)
})
})
/** Like sleep() but 1ms at a time, allows for the event loop to run promises, etc.. */
async function sleepTicks(ms: number) {
for (let i = 0; i < ms; i++) {
await sleep(1)
}
}

async function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

0 comments on commit 54a59f9

Please sign in to comment.