vue-testing-best-practices

Provide best practices for testing Vue.js applications with Vitest, Vue Test Utils, and Playwright.

Updated Nov 3, 2024
One-click install
npx skills add https://github.com/Cancey-Dejean/vue-storybook-starter-clean --skill vue-testing-best-practices-cancey-dejean
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vue-testing-best-practices
Source: https://github.com/Cancey-Dejean/vue-storybook-starter-clean/tree/main/.agents/skills/vue-testing-best-practices
Command: npx skills add https://github.com/Cancey-Dejean/vue-storybook-starter-clean --skill vue-testing-best-practices-cancey-dejean

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and solutions for common challenges encountered when testing Vue.js applications, ensuring robust and maintainable test suites.

Core Features & Use Cases

  • Testing Frameworks: Covers Vitest, Vue Test Utils, and Playwright for unit, component, and E2E testing.
  • Testing Patterns: Explains best practices like the blackbox approach, composable testing, and handling async operations.
  • Common Gotchas: Addresses issues like testing async components, dealing with Teleport, and avoiding snapshot-only tests.
  • Use Case: A developer struggling with intermittent test failures due to race conditions can use this Skill to find and implement the flushPromises pattern to stabilize their tests.

Quick Start

Use the vue-testing-best-practices skill to learn how to test Vue components that use async setup.

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 components with async setup functions?

Testing async Vue components requires handling race conditions by using the flushPromises pattern to stabilize intermittent test failures and ensure accurate assertions.

What is the best way to test Vue.js composables?

Testing Vue.js composables is best achieved using a blackbox approach to validate inputs and outputs. This pattern isolates composable logic and verifies behavior without coupling tests to internal implementation details.

How do I handle Teleport when testing Vue components?

Handling Teleport in Vue component testing involves targeting the teleported content directly in the DOM. You must query the actual destination element rather than the component wrapper to assert rendered output accurately.

Does Vitest work with Vue Test Utils for component testing?

Vitest works seamlessly with Vue Test Utils to provide unit and component testing capabilities. Together they enable component mounting, interaction simulation, and DOM assertion within a fast Vite-powered test environment.

Why are my Playwright e2e tests failing due to intermittent race conditions?

Intermittent Playwright e2e test failures often stem from unhandled asynchronous operations. Implementing proper wait strategies and ensuring asynchronous component states fully resolve before assertions prevents these race conditions.

When should I avoid snapshot-only tests in Vue.js testing?

You should avoid snapshot-only tests when testing Vue.js components because they obscure behavioral logic and fail to validate interactions. Pair snapshots with explicit assertions to ensure component functionality remains robust.