From 887471d3095e7c20068c846073199d7178c741f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Sun, 8 Nov 2026 12:56:51 +0100 Subject: [PATCH] test(browser): pin Date with setSystemTime so it holds under vitest 5.1 --- tests/browser/clock.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/browser/clock.ts b/tests/browser/clock.ts index b1ffd8b5f..b4fedbef4 100644 --- a/tests/browser/clock.ts +++ b/tests/browser/clock.ts @@ -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)); }