Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Vitest’s built-in visual regression testing captures a rendered page or element in Browser Mode and compares it with a reviewed reference screenshot. It is available in Vitest 4 and later; it needs a Browser Mode provider, and it complements—not replaces—tests that verify what the interface does.

How Vitest visual testing works

The toMatchScreenshot() matcher captures rendered output and compares it with a stored image. A mismatch signals that the appearance changed; it does not determine whether the change is correct or explain its cause. Vitest introduced this workflow in Vitest 4.

Use screenshot checks for appearance-sensitive states such as a component’s layout, typography, colors, or spacing. Keep interaction and behavior assertions—for example, whether a button submits a form—in your tests as well. Vitest explicitly says toMatchScreenshot is not a substitute for proper assertions.

Set up Browser Mode and choose a provider

Visual regression tests run in Vitest Browser Mode, which requires a provider. Vitest’s Browser Mode guide names Preview, Playwright, and WebdriverIO. Preview is useful for trying the experience; for CI, the guide requires Playwright or WebdriverIO and recommends Playwright if you do not already use a provider. Follow the setup instructions for your installed Vitest version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
  1. From your project, run vitest init browser to use the official initializer, or install and configure a provider manually.
  2. For a CI workflow, configure Playwright or WebdriverIO as the provider. Choose Preview for local exploration rather than assuming it is the CI provider.
  3. Run the browser tests using your project’s Vitest configuration and ensure the test page renders in the browser context before capturing it.

Provider installation and configuration vary by project and Vitest version. Use the official Browser Mode setup guide rather than copying a configuration intended for a different version.

How to use toMatchScreenshot()

Import the browser APIs in a Browser Mode test, render the UI under test, and then assert against the page or a selected element. For example:

import { expect, test } from 'vitest'
import { page } from 'vitest/browser'

test('primary button matches its approved appearance', async () => {
  // Render or navigate to the UI in the browser context first.
  await page.goto('/button-demo')

  await expect(page.getByRole('button', { name: 'Continue' }))
    .toMatchScreenshot('primary-button')
})

The route and button label are examples: replace them with a page and accessible name in your application. The test must render the target before the matcher captures it. The matcher supports a name and options; consult Vitest’s visual regression guide for configuration supported by your installed version.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Choose the capture scope that answers the question. An element-level screenshot isolates a component and can make unrelated page changes less noisy. A page screenshot checks the composition of a complete screen, but is more exposed to changes elsewhere on that page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Approve and maintain reference screenshots

  1. Run the test for the first time. Vitest creates a reference screenshot and reports that it needs review; the initial failure is part of baseline creation.
  2. Inspect the image. Confirm that it shows the intended design and state. Do not approve an accidental loading screen, missing font, or incomplete layout.
  3. Commit the approved reference with the test suite. Treat it as a reviewed test artifact so later runs have a meaningful comparison target.
  4. Run the test again. Vitest captures the current rendering and compares it with the stored reference.
  5. Investigate a mismatch before updating. Review the reference, actual capture, and diff where available. Update the baseline only when the UI change is intentional and the new image is correct.

The guide’s example updates references with vitest --project vrt --update. Use the project name and command appropriate to your configuration; updating changes what future runs treat as expected, so it is not a substitute for reviewing the new image.

Teams may keep visual tests in a separate project or suite from behavior tests. This can make it clearer that a visual mismatch is an appearance change rather than a failed interaction assertion.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Why screenshot tests can be flaky

Screenshot output depends on the rendering environment, not only on application code. Browser and browser version, operating system, fonts, graphics hardware, headless mode, display settings, and viewport can all affect pixels. Vitest recommends controlling the environment used for capture and comparison.

Vitest also captures repeatedly to assess stability, proceeding when two consecutive screenshots match or when the timeout is reached. This helps with transient loading and rendering differences, but it cannot make content that never settles deterministic. Images loading late, animations, font loading, and shifting layout can all change captures.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Use the same browser version, operating system, fonts, viewport, and headless or CI environment for baseline creation and comparison.
  • Wait for the relevant content to render before capture; use a stable application state rather than relying on timing alone.
  • Disable or reduce animations in the test environment when motion prevents the page from settling.
  • Investigate changing data or layout shifts instead of repeatedly updating references to silence failures.

Read failures and diffs carefully

A failure may include the stored reference, the actual capture, and a diff image when the screenshot dimensions match. Vitest’s guide describes changed pixels in red and anti-aliasing differences in yellow when anti-aliasing is not ignored. The available diff and its presentation depend on the matcher configuration.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Use the diff to locate what changed, then inspect the actual screenshot in context. Anti-aliasing differences can reflect rendering variation, while a shifted element or missing content may indicate a real regression. A threshold can trade sensitivity for tolerance: a looser threshold may reduce noise but can also allow changes to pass. It does not eliminate false positives, and it should not replace environment control or review.

Visual checks versus snapshot and behavior tests

Visual screenshots and serialized value snapshots answer different questions. Vitest’s snapshot guide covers file snapshots; toMatchScreenshot() compares rendered appearance. Neither image comparison nor a file snapshot proves that a control behaves correctly. Pair visual coverage with assertions for the actions and outcomes users rely on.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting Vitest screenshot tests

Symptom Likely cause What to do
Browser tests cannot start Browser Mode has no provider configured, or provider setup does not match the installed Vitest version. Configure a supported provider using the official Browser Mode guide. For CI, use Playwright or WebdriverIO.
The first run fails and creates an image No approved reference exists yet. Review the screenshot, approve it only if it reflects the intended design, and commit it with the suite.
The test changes between local and CI runs Rendering environments differ in browser, OS, fonts, viewport, graphics, or headless/display settings. Standardize the capture and comparison environment, including browser version and viewport.
The screenshot captures a loader or incomplete page The page or its assets have not settled when captured. Wait for the actual content and fonts to load; remove unpredictable data or layout changes from the test state.
The capture never becomes stable Animation or ongoing rendering changes prevent consecutive captures from matching. Disable or reduce animation in the test environment and make the page state deterministic.
A diff is unavailable or hard to interpret Diff availability depends on matching screenshot dimensions; rendering noise can also obscure meaningful changes. Compare the actual and reference images directly, confirm dimensions and environment, then inspect the changed region.
A mismatch appears after an intentional design change The stored baseline still represents the old design. Review the new capture and update the reference only after confirming the change is intended.

Or skip the browser setup

If you need a screenshot outside a Vitest test, ScreenshotNeo is a website screenshot API and MCP server for developers. It does not replace Vitest’s in-browser regression workflow, but it can return a screenshot or PDF from one GET request:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners are accepted and removed before capture, along with supported newsletter popups and chat widgets; these steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan.

Frequently asked questions

Can Vitest visual tests replace end-to-end tests?

No. A screenshot checks how a rendered state looks; use behavior or end-to-end assertions to verify interactions and outcomes.

Does toMatchScreenshot() work outside Browser Mode?

The built-in visual regression workflow described by Vitest runs in Browser Mode and requires a configured provider.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.