writing-tests
Comprehensive guide for writing unit tests, integration tests, and component tests in AiderDesk using Vitest. Use when creating new tests, configuring mocks, or organizing test files.
When & Why to Use This Skill
This Claude skill provides a comprehensive framework and standardized patterns for implementing robust testing strategies in AiderDesk using Vitest and React Testing Library. It guides developers through the entire testing lifecycle—from unit and integration tests to complex component validation—ensuring high code quality, reliable mocking, and efficient test organization.
Use Cases
- Automated Unit Testing: Streamlining the creation of isolated tests for pure functions and core business logic using Vitest and 'vi.mock' for dependency management.
- React Component Validation: Testing UI components in the renderer layer to verify user interactions, prop handling, and DOM rendering using React Testing Library.
- Centralized Mocking: Implementing mock factories and API patterns to ensure consistent behavior across different test contexts and reduce boilerplate code.
- Test Suite Organization: Establishing scalable directory structures, naming conventions, and CLI configurations for better maintainability and test coverage reporting.
| name | Writing Tests |
|---|---|
| description | Comprehensive guide for writing unit tests, integration tests, and component tests in AiderDesk using Vitest. Use when creating new tests, configuring mocks, or organizing test files. |
Writing Tests
Write effective tests using Vitest and React Testing Library.
Quick Start
Create a unit test in src/common/__tests__/utils/math.test.ts:
import { describe, it, expect } from 'vitest';
import { add } from '../../utils/math';
describe('math utility', () => {
it('adds two numbers correctly', () => {
expect(add(1, 2)).toBe(3);
});
});
Run tests with npm run test.
Core Patterns
Unit Testing
Focus on pure functions and logic in src/main or src/common. Use vi.mock() for dependencies.
Component Testing
Test React components in src/renderer. Focus on user interactions and props.
Mocking
Use centralized mock factories for consistent testing across components and contexts.
- references/mocking-guide.md - Mock factories and API patterns
Advanced Usage
For detailed information:
- references/test-organization.md - Directory structure and naming
- references/running-tests.md - CLI commands and coverage
- references/best-practices.md - Principles and patterns
- references/test-patterns.md - Code templates
- assets/test-checklist.md - Pre-flight checklist