mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-13 14:32:03 +00:00
test(browser): pin Date with setSystemTime so it holds under vitest 5.1
This commit is contained in:
1 parent
3f300ad90e
commit
887471d309
1 file changed
+6
-1
@@ -6,9 +6,14 @@
|
||||
* is faked: timers, animation frames and the microtask queue keep running,
|
||||
* which is what Radix, TanStack Query and the URL-state queue wait on.
|
||||
* `setup.ts` restores the real clock after every test.
|
||||
*
|
||||
* `setSystemTime` without fake timers holds `Date` at the given instant.
|
||||
* `useFakeTimers({ toFake: ["Date"] })` did the same until vitest 5.1, where
|
||||
* the faked `Date` moves on with the wall clock and a form submitted a few
|
||||
* hundred milliseconds in no longer sends the pinned instant.
|
||||
*/
|
||||
import { vi } from "vitest";
|
||||
|
||||
export function pinDate(iso: string): void {
|
||||
vi.useFakeTimers({ toFake: ["Date"], now: new Date(iso) });
|
||||
vi.setSystemTime(new Date(iso));
|
||||
}
|
||||
Reference in new issue
Block a user