vitest-visual-testing

Eliminates flaky diffs in Vitest browser-mode visual tests by freezing data, clocks, and animations.

21|1|Updated Jul 22, 2026
One-click install
npx skills add https://github.com/uiverify/uiverify --skill vitest-visual-testing-uiverify
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: vitest-visual-testing
Source: https://github.com/uiverify/uiverify/tree/main/packages/skills/skills/vitest-visual-testing
Command: npx skills add https://github.com/uiverify/uiverify --skill vitest-visual-testing-uiverify

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @uiverify/vitest, vitest, @vitest/browser-playwright.

What problem does it solve? Visual tests over Vitest browser-mode component tests keep coming back "changed" without any real code change, flooding pull requests with false regressions. This Skill diagnoses and fixes the run-to-run variation that the @uiverify/vitest capturer cannot neutralize from outside your app. ## Core Features & Use Cases - Freeze dynamic data: Replace live star counts, contributor lists, tiles, and timestamps with static fixtures via props or vi.mock, removing the entire content-noise class of flaky diffs. - Control time and randomness: Pin the clock with Vitest fake timers and replace unseeded crypto.randomUUID, uuid, or faker values that Math.random seeding cannot cover. - Handle animations and settling: Honor prefers-reduced-motion for infinite JS animations, detect capture with the window.UI_VERIFY global, and await the settled component state before takeSnapshot(). - Use Case: A component suite diffs on every PR because a library tile fetches live star counts. Mock the data module with fixed fixtures, freeze the clock, and the false "changed" verdicts disappear. ## Quick Start Ask the assistant to make my Vitest browser-mode visual tests deterministic by freezing fixtures, the clock, and animations before capture.

Frequently Asked Questions about vitest-visual-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stop flaky visual tests in Vitest browser mode?▼

Feed every component static fixtures instead of live data, freeze the clock with vi.useFakeTimers and vi.setSystemTime, and await the settled component state before takeSnapshot(). The @uiverify/vitest capturer already handles CSS animations, Math.random seeding, and font loading.

How do I mock data for @uiverify/vitest component tests?▼

Pass fixed fixtures as props when the component accepts data directly, or use vi.mock on the data module the component imports internally. MSW in a setup file also works for fetch-based components; the rule is no real network request.

Does @uiverify/vitest handle CSS animations and Math.random automatically?▼

Yes. The capturer kills CSS animations and transitions, disables the Web Animations API, emulates prefers-reduced-motion, seeds Math.random before app code runs, and waits for fonts and images. You only handle infinite JS loops, the clock, and non-Math.random randomness.

Why does my visual test capture a blank or half-rendered component?▼

The snapshot fired before the component settled. render() in vitest-browser-react is async, so await it, then wait for the expected content to appear before calling takeSnapshot() or letting the test end.

How do I handle infinite animations like Lottie or canvas loops in visual tests?▼

Prefer honoring prefers-reduced-motion, which the capturer emulates, using MotionConfig reducedMotion="user" or a useReducedMotion gate. As an escape hatch, detect capture via the window.__UI_VERIFY__ global and render a static end state.

When should I use playwright-visual-testing instead of vitest-visual-testing?▼

Use the Playwright variant for real full pages with scroll, third-party scripts, SSR, and lazy loading. Vitest browser-mode tests render isolated components, so scroll-settling and third-party stubbing concerns do not apply.