Skip to main content
CharleOS uses Vitest for fast, modern unit testing. This page covers how to write and run unit tests.

What to Unit Test

Focus on business logic and utility functions:

Billing Calculations

Value-based billing formula, day rates, prorated revenue

Time Utilities

Working days, t-shirt sizing, time formatting

Data Transformations

Parsing, validation, formatting functions

Helper Functions

Pure functions with deterministic output

Test Structure

File Organization

Basic Test Example

Vitest Features

Test Blocks

Assertions

Async Tests

Common Testing Patterns

Testing Pure Functions

Testing Date Functions

Testing Complex Calculations

Testing with Edge Cases

Running Tests

Basic Commands

Watch Mode

Watch mode automatically reruns tests when files change:
Features:
  • Press a to run all tests
  • Press f to run only failed tests
  • Press t to filter by test name
  • Press p to filter by filename
  • Press q to quit

Test Coverage

Generating Coverage Reports

Coverage Configuration

Coverage Thresholds

Target coverage:
  • Business logic: 80%+
  • Utilities: 90%+
  • Components: Not required

Mocking

Mocking Functions

Mocking Modules

Best Practices

Focus on what the function does, not how:
Test names should describe the scenario:
Tests should not depend on each other:
Don’t just test the happy path:

Debugging Tests

Using Console

Using Vitest UI

Opens a browser-based UI for exploring tests.

Debugging in VS Code

Add to .vscode/launch.json:

Testing Overview

Testing strategy and tools

E2E Tests

End-to-end testing with Playwright

Vitest Docs

Official Vitest documentation