-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Documentation is
- Missing
- Outdated
- Confusing
- Not sure?
Explain in Detail
Docs state that toFake defaults to "everything available globally except nextTick and queueMicrotask", which should include performance.
However, performance.now() is not faked unless explicitly specified:
import { beforeEach, expect, it, vi } from 'vitest';
beforeEach(() => {
vi.useFakeTimers();
});
it('fails - performance.now not advancing', () => {
const start = performance.now();
vi.advanceTimersByTime(100);
expect(performance.now() - start).toBe(100); // fails: expected 100, got 0.1....
});Requires:
vi.useFakeTimers({ toFake: ['performance'] });Similarly, https://vitest.dev/api/vi states:
If fake timers are enabled, this method simulates a user changing the system clock (will affect date related API like hrtime, performance.now or new Date())
and
vi.useFakeTimers() does not automatically mock process.nextTick and queueMicrotask. But you can enable it by specifying the option in toFake argument: vi.useFakeTimers({ toFake: ['nextTick', 'queueMicrotask'] }).
Which appear to be wrong / incomplete
Your Suggestion for Changes
Update docs to remove performance, possibly others, from list of default mocked timers
Reproduction
No response