Agent skill
test-vue-composable
Guide for unit testing Vue 3 Composables using Vitest. Use this skill when writing tests for Vue logic to determine the correct testing strategy based on whether the composable is independent, relies on lifecycle hooks (onMounted), or uses dependency injection (provide/inject).
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/vue-test-composable
SKILL.md
Vue Composable Testing Guide (Vitest)
1. Determine Composable Type
Analyze the source code of the composable to determine the testing strategy:
- Independent: Uses only Reactivity APIs (
ref,computed,watch). Does not use Lifecycle hooks orinject. - Dependent (Lifecycle): Uses Lifecycle hooks (e.g.,
onMounted,onUnmounted). - Dependent (Injection): Uses
injectto retrieve dependencies.
2. Select Testing Strategy
A. Independent Composables
Test directly by invoking the function and asserting the returned state. No mocking of the Vue instance is required.
- Pattern: Import composable -> Call it -> Assert
result.value. - Reference: See
references/examples.md(Section: Independent)
B. Dependent Composables (Lifecycle)
Requires a component context to trigger hooks like onMounted. Use the withSetup helper function.
- Prerequisite: Ensure
test-utils.ts(or similar) exists containing thewithSetuphelper.- Action: If the helper is missing, generate it using
references/helpers.md.
- Action: If the helper is missing, generate it using
- Pattern: Import
withSetup-> CallwithSetup(() => useComposable())-> Destructure result -> Assert. - Reference: See
references/examples.md(Section: Lifecycle Dependent)
C. Dependent Composables (Injection)
Requires a provider context. Use the useInjectedSetup helper function.
- Prerequisite: Ensure
test-utils.tscontains theuseInjectedSetuphelper.- Action: If the helper is missing, generate it using
references/helpers.md.
- Action: If the helper is missing, generate it using
- Pattern: Define injection config array -> Call
useInjectedSetup-> Assert -> Call unmount(). - Reference: See
references/examples.md(Section: Injection Dependent)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?