Sets virtual clock to a fixed date

This commit is contained in:
Henning Dieterichs
2026-05-14 21:22:18 +02:00
parent 1a2b823d90
commit 2d03d75c49

View File

@@ -893,7 +893,14 @@ export function defineComponentFixture(options: ComponentFixtureOptions): Themed
// during dispose to drain async cleanup work (e.g. `Promise.race`
// guards behind `timeout(1000)` that hold references until they
// settle) before the leak tracker checks for undisposed objects.
const clock = new VirtualClock(Date.now());
//
// Seed the clock with a fixed wall-clock time so any code under
// test that reads `Date.now()` / `new Date()` produces the same
// values run after run. Real time would otherwise leak in
// through this seed and make screenshots that include
// time-derived labels (e.g. "1 hour ago", "Today") drift
// across days, hour boundaries, and DST changes.
const clock = new VirtualClock(new Date('2026-05-14T12:00:00Z').getTime());
const p = new VirtualTimeProcessor(
clock,
drainMicrotasksEmbedding(realTimeApi),