Skip to main content
AppShell uses Vitest for fast, modern testing with excellent TypeScript support and React component testing.

Test Framework

The core package uses:
  • Vitest: Fast unit test runner (compatible with Jest API)
  • @testing-library/react: React component testing utilities
  • happy-dom: Lightweight DOM implementation for tests

Running Tests

Run All Tests

From the repository root:
This runs tests across all packages using Turborepo.

Run Core Package Tests

To run tests specifically in the core package:

Watch Mode

Run tests in watch mode during development:

Run Specific Test Files

Test Configuration

The test setup is defined in packages/core/vitest.config.ts:
Key Configuration:
  • environment: “happy-dom”: Provides a lightweight DOM for component testing
  • tsconfigPaths: Resolves TypeScript path aliases from tsconfig.json

Writing Tests

Component Tests

Use React Testing Library to test components:

Hook Tests

Test custom hooks with @testing-library/react:

Testing with Context

Wrap components with required providers:

Test Organization

File Naming

Place test files next to the code they test:

Test Structure

Organize tests using describe blocks:

Code Quality

Type Checking

Run TypeScript type checking:
This runs across all packages and ensures type safety.

Linting

Lint the core package:

Test Coverage

Generate coverage reports:
This creates a coverage report showing tested vs untested code.

Continuous Integration

Tests run automatically on:
  • Pull requests to main
  • Before publishing packages
  • As part of the release process
Ensure all tests pass before submitting a PR.

Best Practices

1

Test user behavior, not implementation

Focus on testing what users see and interact with, not internal component state or implementation details.
2

Use meaningful test descriptions

Write clear describe and it statements that explain what is being tested.
3

Keep tests isolated

Each test should be independent and not rely on the state from other tests.
4

Mock external dependencies

Use Vitest’s mocking capabilities to isolate components from external APIs or services.
5

Test accessibility

Use Testing Library’s accessibility queries (getByRole, getByLabelText) to ensure components are accessible.

Debugging Tests

Run in UI Mode

Vitest provides an interactive UI for debugging:

Use Console Logs

Debug component output:

VS Code Debugging

Add a .vscode/launch.json configuration: