fake timer doesn't auto advance for browser mode actions
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- react, typescript
- Domain
- testing-qa
Research direction
Start by running the provided example.spec.tsx reproduction with the browser runner, fake timers, and the React component shown. Trace how browser-mode actions and the setTimeout-driven button appearance interact, then add a regression test covering the example; done means the button becomes available and click completes without the timeout.
Written by the indexing model from the issue text.
Description
Describe the bug
When using vi.useFakeTimers(), commands like .click do not work, but they do with real timers
Reproduction
// example.spec.tsx
import { useEffect, useState } from "react";
import { test, vi } from "vitest";
import { page } from "vitest/browser";
import { render } from "vitest-browser-react";
const TestComponent = () => {
const [show, setShow] = useState(false);
useEffect(() => {
setTimeout(() => setShow(true), 1000);
}, []);
if (!show) {
return null;
}
return <button>Click me!</button>;
};
test("failed with fake timers", async ({ onTestFinished }) => {
vi.useFakeTimers();
onTestFinished(() => vi.useRealTimers());
await render(<TestComponent />);
await page.getByRole("button").click();
});
With fake timers
❯ chromium src/example.spec.tsx (1 test | 1 failed) 15012ms
× failed with fake timers 15011ms
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL chromium src/example.spec.tsx > failed with fake timers
TimeoutError: locator.click: Timeout 14888ms exceeded.
Call log:
- waiting for locator('[data-vitest="true"]').contentFrame().getByRole('button')
Failure screenshot:
- src/__screenshots__/example.spec.tsx/failed-with-fake-timers-1.png
❯ src/example.spec.tsx:27:33
25| await render(<TestComponent />);
26|
27| await page.getByRole("button").click();
| ^
28| });
29|
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Test Files 1 failed (1)
Tests 1 failed (1)
Start at 21:59:18
Duration 16.71s (transform 0ms, setup 0ms, import 100ms, tests 15.01s, environment 0ms)
Without fake timers
✓ chromium src/example.spec.tsx (1 test) 1496ms
✓ failed with fake timers 1495ms
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 22:00:30
Duration 3.12s (transform 0ms, setup 0ms, import 112ms, tests 1.50s, environment 0ms)
System Info
System:
OS: Windows 11 10.0.26200
CPU: (8) x64 Intel(R) Core(TM) i3-10100F CPU @ 3.60GHz
Memory: 16.16 GB / 31.93 GB
Binaries:
Node: 22.21.1 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\node.EXE
Yarn: 1.22.22 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\yarn.CMD
npm: 11.12.1 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\npm.CMD
pnpm: 10.33.0 - C:\Users\Micha\AppData\Local\mise\installs\node\22.21.1\pnpm.CMD
Browsers:
Chrome: 146.0.7680.165
Edge: Chromium (142.0.3595.69)
npmPackages:
@vitejs/plugin-react: ^6.0.1 => 6.0.1
@vitest/browser-playwright: ^4.1.2 => 4.1.2
vite: ^8.0.1 => 8.0.3
vitest: ^4.1.2 => 4.1.2
vitest-browser-react: ^2.1.0 => 2.1.0
Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
- Dominant language
- TypeScript
- Stars
- 17.1k
- Forks
- 2k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 92
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vitest-dev/vitest
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
vitest-dev/vitest#11276 · 3 reactions ·
-
p3-minor-bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
vitest-dev/vitest#11144 · 1 comment ·
-
pending triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
vitest-dev/vitest#11019 · 5 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
vitest-dev/vitest#10940 ·
-
p2-nice-to-have
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
vitest-dev/vitest#10793 · 1 comment ·
All issues in vitest-dev/vitest
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·