vue-testing-best-practices

Guides Vue 3 testing with Vitest, Vue Test Utils, Pinia, and Playwright patterns.

Updated Aug 22, 2026
One-click install
npx skills add https://github.com/falentio/cimi --skill vue-testing-best-practices-falentio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-testing-best-practices
Source: https://github.com/falentio/cimi/tree/main/.agents/skills/vue-testing-best-practices
Command: npx skills add https://github.com/falentio/cimi --skill vue-testing-best-practices-falentio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Vue 3 tests often fail intermittently or break during refactoring because of async timing issues, missing Pinia setup, Suspense requirements, and implementation-coupled assertions. This Skill provides targeted guidance for diagnosing and fixing these common testing problems. ## Core Features & Use Cases - Async Testing Patterns: Handle race conditions with flushPromises, nextTick, and proper awaiting of trigger and setValue calls. - Environment Setup: Configure Vitest, testing Pinia stores with createTestingPinia, and testing composables that use lifecycle hooks or inject. - Edge Case Handling: Test async setup components with Suspense wrappers, teleported content, and defineAsyncComponent loading states. - Use Case: When a test fails with "injection Symbol(pinia) not found" or an async component never renders, consult the matching reference to apply the correct fix with code examples. ## Quick Start Ask how to fix a Vue test that fails intermittently due to async updates, and follow the referenced guidance for flushPromises and nextTick usage.

Frequently Asked Questions about vue-testing-best-practices

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

FAQPage Schema
How do I test Vue 3 components with Vitest and Vue Test Utils?

Install vitest, @vue/test-utils, and happy-dom, then configure the test environment in vite.config.js. Mount components with mount(), simulate interactions with awaited trigger() calls, and assert on rendered output and emitted events.

Why do Vue tests fail with injection Symbol(pinia) not found?

This error occurs when components using Pinia stores are mounted without an active Pinia instance. Use createTestingPinia from @pinia/testing in the global plugins option for component tests, or call setActivePinia(createPinia()) in beforeEach for store unit tests.

How to test Vue async components with Suspense?

Components with async setup must be wrapped in a Suspense boundary during testing. Create a wrapper component containing Suspense, mount it, then call await flushPromises() before making assertions on the resolved component via findComponent().

Playwright vs Cypress for Vue E2E testing?

Playwright offers full cross-browser support including WebKit, built-in parallelization, and is fully open source. Cypress has limited WebKit support and requires paid subscriptions for some features, making Playwright the recommended choice for new Vue E2E setups.

Why do Vue tests fail intermittently with race conditions?

Vue updates the DOM asynchronously, so assertions may run before updates complete. Always await trigger() and setValue() calls, use nextTick for reactive state changes, and use flushPromises for external async operations like API calls.

Can Vue Test Utils find teleported content in tests?

No, wrapper.find() cannot locate teleported content because it renders outside the component's DOM tree. Stub Teleport in unit tests, or mount with attachTo document.body and query the real DOM for integration tests.