vitest-testing
Vitest unit testing for TypeScript/JavaScript in Oh My Brand! theme. Test setup, Web Component testing, mocking patterns, and coverage. Use when writing unit tests for frontend code.
Best use case
vitest-testing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Vitest unit testing for TypeScript/JavaScript in Oh My Brand! theme. Test setup, Web Component testing, mocking patterns, and coverage. Use when writing unit tests for frontend code.
Teams using vitest-testing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/vitest-testing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How vitest-testing Compares
| Feature / Agent | vitest-testing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Vitest unit testing for TypeScript/JavaScript in Oh My Brand! theme. Test setup, Web Component testing, mocking patterns, and coverage. Use when writing unit tests for frontend code.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# Vitest Testing
Unit testing TypeScript/JavaScript code with Vitest for the Oh My Brand! WordPress FSE theme.
---
## When to Use
- Writing unit tests for Web Components
- Testing utility functions (debounce, throttle, etc.)
- Mocking browser APIs (IntersectionObserver, matchMedia)
- Achieving code coverage requirements
---
## Configuration
| File | Template | Purpose |
|------|----------|---------|
| [vitest.config.ts](references/vitest.config.ts) | Vitest configuration | Test settings and coverage |
| [setup.ts](references/setup.ts) | Test setup | Browser API mocks |
---
## Test Templates
| Template | Purpose |
|----------|---------|
| [web-component.test.ts](references/web-component.test.ts) | Web Component tests |
| [debounce.test.ts](references/debounce.test.ts) | Utility function tests |
| [mocking-patterns.ts](references/mocking-patterns.ts) | Mocking examples |
---
## Test Structure
```typescript
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
describe('ComponentName', () => {
let element: HTMLElement;
beforeEach(() => {
document.body.innerHTML = `<my-component></my-component>`;
element = document.querySelector('my-component')!;
});
afterEach(() => {
document.body.innerHTML = '';
});
it('should initialize correctly', () => {
expect(element).toBeDefined();
});
});
```
---
## Mock Patterns Quick Reference
### Mock Functions
```typescript
const mockFn = vi.fn();
mockFn.mockReturnValue('value');
mockFn.mockResolvedValue({ data: [] });
expect(mockFn).toHaveBeenCalledWith('arg');
```
### Mock Timers
```typescript
vi.useFakeTimers();
vi.advanceTimersByTime(100);
vi.useRealTimers();
```
### Spy on Methods
```typescript
const spy = vi.spyOn(object, 'method');
spy.mockReturnValue('mocked');
expect(spy).toHaveBeenCalled();
```
See [mocking-patterns.ts](references/mocking-patterns.ts) for complete examples.
---
## Coverage
### Thresholds
| Metric | Threshold |
|--------|-----------|
| Statements | 80% |
| Branches | 80% |
| Functions | 80% |
| Lines | 80% |
### What to Test
**Always test:**
- Public methods and functions
- Edge cases (empty arrays, null values)
- Error handling paths
- User interactions
- Attribute change callbacks
**Don't test:**
- Third-party library internals
- Private implementation details
- Simple getters/setters
---
## Running Tests
| Command | Purpose |
|---------|---------|
| `pnpm test` | Run all tests |
| `pnpm run test:watch` | Watch mode |
| `pnpm run test:coverage` | With coverage |
| `pnpm test -- --testNamePattern="nav"` | Filter by name |
| `pnpm test src/blocks/gallery/` | Specific directory |
---
## Related Skills
- [typescript-standards](../typescript-standards/SKILL.md) - TypeScript conventions
- [web-components](../web-components/SKILL.md) - Web Component patterns
- [phpunit-testing](../phpunit-testing/SKILL.md) - PHP unit testing
- [playwright-testing](../playwright-testing/SKILL.md) - E2E testing
---
## References
- [Vitest Documentation](https://vitest.dev/)
- [Testing Library](https://testing-library.com/)
- [Web Components Testing](https://open-wc.org/docs/testing/testing-package/)Related Skills
webapp-testing
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
web3-testing
Test smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or va...
vue-playwright-testing
Comprehensive guide for testing Vue 3 applications with Playwright (2025). This skill should be used when writing end-to-end tests or component tests for Vue apps, testing Vue Router navigation, reactive state changes, authentication flows, or setting up Playwright in Vue projects.
unit-testing-test-automator
Master AI-powered test automation with modern frameworks, self-healing tests, and comprehensive quality engineering. Build scalable testing strategies with advanced CI/CD integration. Use PROACTIVELY for testing automation or quality assurance. Use when: the task directly matches test automator responsibilities within plugin unit-testing. Do not use when: a more specific framework or task-focused skill is clearly a better match.
typescript-testing
Comprehensive testing guidance for TypeScript projects including unit testing patterns, mocking strategies, and test organization best practices
testing-tauri-apps
Guides developers through testing Tauri applications including unit testing with mock runtime, mocking Tauri APIs, WebDriver end-to-end testing with Selenium and WebdriverIO, and CI integration with GitHub Actions.
testing-strategy-python
Python/FastAPI/Django testing conventions. pytest, fixtures, httpx, TestClient, factory_boy. Use when writing or reviewing Python tests.
testing-strategy-builder
Use this skill when creating comprehensive testing strategies for applications. Provides test planning templates, coverage targets, test case structures, and guidance for unit, integration, E2E, and performance testing. Ensures robust quality assurance across the development lifecycle.
testing-skills-activation
Use when creating or refining Claude Code skills to validate that skill descriptions trigger correctly - provides systematic testing methodology for skill activation patterns using test cases and automated evaluation
Testing Skill
Automatiza pruebas y diagnósticos del sistema SmartK et sin perder tiempo
testing-qa
Comprehensive testing and QA workflow covering unit testing, integration testing, E2E testing, browser automation, and quality assurance.
testing-principles
Language-agnostic testing principles including TDD, test quality, coverage standards, and test design patterns. Use when writing tests, designing test strategies, or reviewing test quality.