vitest-browser-vue is a library designed for rendering Vue 3 components within Vitest's browser testing environment, adhering to the principles of `@testing-library`. It facilitates writing integration tests by exposing Vitest `locators` and utilities that mimic how users interact with components in a real browser. The current stable version is 2.1.0, with releases occurring regularly, indicating active development and maintenance. A key differentiator from `@testing-library/vue` is its cleanup strategy: it cleans up the component *before* a test starts, rather than after, allowing developers to inspect the rendered UI during debugging. It integrates seamlessly with Vitest's `page.render` and `cleanup` methods and leverages `@vue/test-utils` under the hood for component mounting and interaction. Users must ensure compatibility with `vitest` version `4.0.0` or higher and `vue` version `3.0.0` or higher.
npm install vitest-browser-vueVerified import paths — ran on the pinned version, not inferred.
Demonstrates rendering a Vue component, interacting with it using Vitest locators, and asserting its state, utilizing the default `render` function.
Review Vitest v4 migration guide and update test files and configurations to match the new syntax requirements. Specifically, ensure Vitest is at least `^4.0.0-0`.
Upgrade your `vitest` dependency to version `4.0.18` or newer to prevent `data-testid` attributes from appearing in snapshots.
Add `vitest-browser-vue` to your `compilerOptions.types` array in `tsconfig.json`, or explicitly include `'vitest-browser-vue'` in your `vitest.config.ts`'s `setupFiles` array to ensure type definitions are loaded.
To disable auto-cleanup and manage it manually (e.g., `screen.cleanup()`), import `render` from `vitest-browser-vue/pure`.