writing-tests
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
Debugging Failing Tests
- Read the error output and identify the failing assertion
- Check mock setup — verify
vi.mock()paths and return values match expectations - For component tests, inspect rendered output with
screen.debug() - Run a single test in isolation:
npm run test:node -- --no-color -t "test name" - Verify coverage:
npm run test:coverageto confirm new code is tested
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
More from hotovo/aider-desk
skill-creator
Create AiderDesk Agent Skills by writing SKILL.md files, defining frontmatter metadata, structuring references, and organizing skill directories. Use when building a new skill, creating a SKILL.md, planning skill architecture, or writing skill content.
73agent-creator
Create and configure AiderDesk agent profiles by defining tool groups, approval rules, subagent settings, and provider/model selection. Use when setting up a new agent, creating a profile, or configuring agent tools and permissions.
69theme-factory
Create new AiderDesk UI themes by defining SCSS color variables, registering theme types, and adding i18n display names. Use when adding a theme, creating a color scheme, customizing appearance, or implementing dark mode and light mode variants.
61extension-creator
Create AiderDesk extensions by setting up extension files, defining metadata, implementing Extension interface methods, and updating documentation. Use when building a new extension, creating extension commands, tools, or event handlers.
19