vitest-browser-vue

Render Vue components in Vitest Browser Mode
2,918,771 79
Install
npm install vitest-browser-vue
Latest Version:3.1.0
Vue:3
License:MIT
Last Updated:Sep 4, 2026
Links: GitHub  ·  npm
Maintainer: ariperkkio

vitest-browser-vue

Docs | Package

Render Vue components in Vitest Browser Mode. This library follows testing-library principles and exposes only locators and utilities that encourage you to write tests that closely resemble how your Vue components are used.

Requires vitest 4.0.0 or higher.

import { render } from 'vitest-browser-vue'
import { expect, test } from 'vitest'

test('counter button increments the count', async () => {
  const screen = await render(Component, {
    props: {
      initialCount: 1,
    }
  })

  await screen.getByRole('button', { name: 'Increment' }).click()

  await expect.element(screen.getByText('Count is 2')).toBeVisible()
})

vitest-browser-vue also automatically injects render and cleanup methods on the page. Example:

// vitest.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    // if the types are not picked up, add `vitest-browser-vue` to
    // "compilerOptions.types" in your tsconfig or
    // import `vitest-browser-vue` manually so TypeScript can pick it up
    setupFiles: ['vitest-browser-vue'],
    browser: {
      // ... your config
    },
  },
})
import { page } from 'vitest/browser'

test('counter button increments the count', async () => {
  const screen = await page.render(Component, {
    props: {
      initialCount: 1,
    }
  })

  screen.cleanup()
})

Unlike @testing-library/vue, vitest-browser-vue cleans up the component before the test starts instead of after, so you can see the rendered result in your UI. To avoid auto-cleanup, import the render function from vitest-browser-vue/pure.

Configuration

You can change the global configuration by modifying the config export. You can import it from both vitest-browser-vue and vitest-browser-vue/pure. See documentation.

import { config } from 'vitest-browser-vue'

config.global.mocks = {
  $t: text => text
}

Special thanks

Related Packages

@ohos-ports/vitest-browser-vue

Render Vue components in Vitest Browser Mode

0 6
@i18n-micro/test-utils

Testing helpers for Nuxt I18n Micro (translations, locales, formatting mocks).

152,219 251
nuxt-vitest-shared-app

Run Nuxt component tests in Vitest on one shared app per worker, with per-test c...

546 0
@aiao/rxdb-test

Cross-framework fixtures and test utilities for Aiao RxDB packages.

3,999 1
vue3-snapshot-serializer

Vitest snapshot serializer for Vue 3 components

369,150 16

Version History

Version Released Vue License
3.1.0 ^3.0.0 MIT
3.0.0 ^3.0.0 MIT
2.1.0 ^3.0.0 MIT
2.0.2 ^3.0.0 MIT
2.0.1 ^3.0.0 MIT
Pre-releases (1)
Version Released Vue License
2.0.0-beta.1 ^3.0.0 MIT