vitest-testing
Vitest testing framework patterns and best practices. Use when writing unit tests, integration tests, configuring vitest.config, mocking with vi.mock/vi.fn, using snapshots, or setting up test coverage. Triggers on describe, it, expect, vi.mock, vi.fn, beforeEach, afterEach, vitest.
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/anderskev/vitest-testingWhat This Skill Does
The vitest-testing skill provides comprehensive support for the Vitest framework, the leading unit testing tool for the Vite ecosystem. It acts as an expert assistant that understands the nuance of modern JavaScript and TypeScript testing. Whether you are migrating from Jest, setting up a new project, or debugging complex asynchronous code, this skill provides the context needed to write clean, maintainable, and robust test suites. It handles everything from simple assertions and object deep equality checks to sophisticated mocking, timer manipulation, and environment configuration.
Installation
To integrate this skill into your environment, run the following command in your terminal:
clawhub install openclaw/skills/skills/anderskev/vitest-testing
Ensure that you have Vitest installed as a development dependency in your project's package.json to allow the agent to verify your local configuration against the framework's best practices.
Use Cases
- Unit Testing: Writing isolated tests for individual functions or components, ensuring logic paths are covered with edge cases.
- Integration Testing: Orchestrating multiple modules to verify that they work together correctly, utilizing
vi.mockto stub dependencies. - Configuration Management: Optimizing
vitest.config.tsfiles, setting up coverage reporters, and defining test environments likejsdomornode. - Mocking Strategy: Creating consistent mock environments for APIs, timers, and external services to maintain deterministic test results.
- Refactoring: Safely modifying existing code by creating a robust suite of regression tests before executing changes.
Example Prompts
- "Create a Vitest unit test for my
calculateTaxfunction that covers the standard rate, high-income threshold, and invalid input scenarios." - "I am having trouble mocking an external module with
vi.mock. Here is my current code, can you identify why the mock isn't being applied correctly?" - "Convert my existing Jest test file to Vitest syntax, ensuring that my
beforeEachhooks and snapshot assertions are migrated accurately."
Tips & Limitations
To get the best performance, always ensure you are using await with promise-based assertions. A common pitfall is failing to await expect(promise).resolves, which can lead to false positives where tests pass even if the code fails. Always use vi.clearAllMocks() or vi.resetAllMocks() in your cleanup hooks to prevent state pollution between tests, which is the most frequent source of flaky test suites. While this skill is highly effective at writing boilerplate and configuration, always review mock logic to ensure it accurately reflects real-world API behavior. For complex system interactions, consider combining this with integration testing tools to verify that your mocks haven't diverged from actual interface implementations.
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-anderskev-vitest-testing": {
"enabled": true,
"auto_update": true
}
}
}Tags(AI)
Flags: code-execution
Related Skills
tutorial-docs
Tutorial patterns for documentation - learning-oriented guides that teach through guided doing
fetch-pr-feedback
Fetch review comments from a PR and evaluate with receive-feedback skill
swift-testing-code-review
Reviews Swift Testing code for proper use of
rust-testing-code-review
Reviews Rust test code for unit test patterns, integration test structure, async testing, mocking approaches, and property-based testing. Covers Rust 2024 edition changes including async fn in traits for mocks,
explanation-docs
Explanation documentation patterns for understanding-oriented content - conceptual guides that explain why things work the way they do