-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
advanceTimers
option (#907)
Co-authored-by: Philipp Fritsche <[email protected]>
- Loading branch information
1 parent
2b9d00f
commit 627a5cf
Showing
5 changed files
with
35 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
export function wait(time?: number) { | ||
return new Promise<void>(resolve => setTimeout(() => resolve(), time)) | ||
import {Config} from '../../setup' | ||
|
||
export function wait(config: Config) { | ||
const delay = config.delay | ||
if (typeof delay !== 'number') { | ||
return | ||
} | ||
return Promise.all([ | ||
new Promise<void>(resolve => setTimeout(() => resolve(), delay)), | ||
config.advanceTimers(delay), | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {wait} from '#src/utils/misc/wait' | ||
|
||
test('advances timers when set', async () => { | ||
jest.useFakeTimers() | ||
jest.setTimeout(50) | ||
// If this wasn't advancing fake timers, we'd timeout and fail the test | ||
await wait(10000, jest.advanceTimersByTime) | ||
jest.useRealTimers() | ||
}) |