-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(browser): don't fail when calling vi.useFakeTimers (#4992)
- Loading branch information
1 parent
8877e22
commit 6c5fe49
Showing
4 changed files
with
33 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { afterEach, expect, it, vi } from 'vitest' | ||
|
||
afterEach(() => { | ||
vi.useRealTimers() | ||
}) | ||
|
||
it('only runs a setTimeout callback once (ever)', () => { | ||
vi.useFakeTimers() | ||
|
||
const fn = vi.fn() | ||
setTimeout(fn, 0) | ||
expect(fn).toHaveBeenCalledTimes(0) | ||
|
||
vi.runAllTimers() | ||
expect(fn).toHaveBeenCalledTimes(1) | ||
|
||
vi.runAllTimers() | ||
expect(fn).toHaveBeenCalledTimes(1) | ||
}) |