Skip to main content

Testing Philosophy

We follow a comprehensive testing strategy that balances coverage with development speed:
  • Unit Tests - Test individual functions and components in isolation
  • Integration Tests - Test how components work together
  • End-to-End Tests - Test complete user flows in a real browser
Follow the testing pyramid: Many unit tests, fewer integration tests, and selective E2E tests for critical paths.

Testing Stack

Our testing infrastructure uses modern, industry-standard tools:
  • Vitest - Fast unit test runner
  • React Testing Library - Component testing utilities
  • Playwright - End-to-end testing framework
  • MSW (Mock Service Worker) - API mocking

Unit Testing

Setup

Vitest configuration in vitest.config.ts:

Test Setup File

Configure test environment in src/test/setup.ts:

Testing Components

1

Basic Component Test

Test component rendering and basic interactions:
2

Testing with Props

Test different prop combinations:
3

Testing Hooks

Test custom React hooks:

Testing Utilities

Create reusable test utilities in src/test/utils.tsx:

Integration Testing

API Mocking with MSW

Set up Mock Service Worker for API mocking:
Configure MSW in test setup:

Testing API Integration

End-to-End Testing

Playwright Setup

Configure Playwright in playwright.config.ts:

Writing E2E Tests

Advanced E2E Patterns

Reuse authentication state across tests:
Mock API responses in E2E tests:

Running Tests

Test Coverage

Maintain high test coverage for critical code:
Coverage Goals:
  • Statements: > 80%
  • Branches: > 75%
  • Functions: > 80%
  • Lines: > 80%
Don’t obsess over 100% coverage. Focus on testing critical paths and complex logic.

Best Practices

Do’s

  • Write tests alongside your code
  • Test user behavior, not implementation details
  • Use descriptive test names
  • Keep tests isolated and independent
  • Mock external dependencies
  • Test error states and edge cases

Don’ts

  • Don’t test third-party libraries
  • Don’t test implementation details (CSS classes, state)
  • Don’t write flaky tests
  • Don’t skip tests without good reason
  • Don’t have test dependencies on each other

Testing Accessibility

Include accessibility testing in your component tests to catch a11y issues early.