Testing Skill
Purpose
Generate test files and testing utilities for Vue 3 applications with proper coverage and best practices.
Test File Generation Rules
IMPORTANT: Test files MUST be generated alongside UI components, views, stores, directives, and utilities.
When generating any of the following, ALWAYS create a corresponding test file:
- •Vue Components (
src/components/**/*.vue) →{ComponentName}.spec.tsin same directory - •Views (
src/views/**/*.vue) →{ViewName}.spec.tsin same directory - •Store Modules (Vuex:
src/store/modules/*.ts, Pinia:src/stores/*.ts) →{moduleName}.spec.tsin same directory - •Directives (
src/directives/*.ts) →{directiveName}.spec.tsin same directory - •Utilities (
src/shared/utils/*.ts) →{utilityName}.spec.tsin same directory - •Mixins (
src/shared/mixins/*.ts) →{mixinName}.spec.tsin same directory - •Services (
src/services/*.ts) → OPTIONAL - typically mocked in component tests
Test File Location
- •Test files live co-located with their source files (not in separate
tests/directory) - •Naming convention:
{filename}.spec.ts(use.spec.tsconsistently)
Testing Frameworks
Jest Testing (if test_framework: jest)
- •Use Jest with Vue Test Utils (
@vue/test-utils) for component testing - •Use
@vue/vue3-jesttransformer for.vuefiles - •Use
ts-jestfor TypeScript files - •Mock external dependencies (axios, router, store)
- •Target >80% coverage for services and stores
- •Target >70% coverage for components
- •Test file naming:
{filename}.spec.ts - •Configuration:
jest.config.cjs(handled by jest-config skill)
Vitest Testing (if test_framework: vitest)
- •Use Vitest with Vue Test Utils for component testing
- •Native ESM support with faster execution
- •Use
@vitest/uifor interactive test UI - •Mock external dependencies (axios, router, store)
- •Target >80% coverage for services and stores
- •Target >70% coverage for components
- •Test file naming:
{filename}.spec.tsor{filename}.test.ts - •Configuration:
vitest.config.ts(handled by vitest-config skill)
Test Coverage Requirements
- •Components: >70% coverage (focus on user interactions, computed properties, methods)
- •Views: >70% coverage (lifecycle, navigation, major workflows)
- •Stores: >80% coverage (state mutations, actions, getters)
- •Utilities: >80% coverage (all functions and edge cases)
- •Directives: >70% coverage (behavior and DOM manipulation)
Test Organization Best Practices
- •Describe blocks: Group related tests logically
- •Component/View name as top-level describe
- •Group by: lifecycle hooks, computed properties, methods, events
- •Test naming: Use descriptive test names that explain expected behavior
- •AAA Pattern: Arrange, Act, Assert in each test
- •Mocking: Mock external dependencies (API calls, router, store)
- •Cleanup: Use
afterEachto clear mocks and reset state - •Isolation: Each test should be independent and not rely on others
Example Files
See: examples.md in this directory for complete test templates:
- •Component tests (Options API)
- •Component tests (Composition API)
- •View tests
- •Store tests (Vuex)
- •Store tests (Pinia)
Notes
- •Test templates vary based on
vue_api_pattern(composition-api vs options-api) - •Test templates vary based on
state_management(pinia vs vuex) - •All test files should use the same testing framework specified in configuration
- •Co-location of tests with source files improves maintainability