new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vitest · Guide · all subjects

mocking timers

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Fake timers and setSystemTime now mock Temporal

In Vitest 5.0, fake timers now mock the Temporal API alongside Date. When Temporal is available on the global object (natively or through a polyfill), Temporal.Now keeps returning the real wall-clock time unless vi.useFakeTimers() is active. Now it follows the mocked clock. This is controlled by fakeTimers.toFake and fakeTimers.toNotFake options.

vi.useFakeTimers for mocking timers

vi.useFakeTimers() enables fake timers. This allows tests to control time advancement with vi.advanceTimersByTime(). Call vi.useRealTimers() to restore real timers.

vi.setSystemTime for setting system time

vi.setSystemTime(time) sets the mocked system time, which affects Date and Temporal APIs. In Vitest 5.0, it now also mocks Temporal.Now when vi.useFakeTimers() is active.

fakeTimers.toFake and toNotFake options control which APIs are mocked

fakeTimers.toFake and fakeTimers.toNotFake control which global objects and methods are mocked when fake timers are enabled. Temporal is part of the default set of faked APIs.

Vitest does not support Jest's legacy timers

Vitest does not support Jest's legacy timers API. Use vi.useFakeTimers() and vi.useRealTimers() instead.

Give your agent this brain