Skip to main content

Overview

Integration tests in the Bitwarden clients repository verify that multiple components work together correctly. These tests use the same Jest framework as unit tests but focus on testing service interactions, API integrations, and data flow between components.

Integration Test Patterns

While the repository uses .spec.ts for all Jest tests, integration tests differ from unit tests by:
  • Testing multiple services together
  • Using real implementations where possible
  • Verifying end-to-end data flow
  • Testing API service interactions

Service Integration Tests

Import Service Example

Example from libs/importer/src/services/import.service.spec.ts:

Testing Multi-Service Workflows

Account Service Integration

Using the FakeAccountService from test utilities:

API Service Integration Tests

Testing API Calls

Testing State Management

State Service Integration

Testing Data Importers

Importer Integration Tests

Example testing various importers:

Testing RxJS Observables

Observable Chain Testing

Best Practices

1. Minimize Mocking

  • Use real implementations of simple utilities and models
  • Only mock external dependencies (API, storage, crypto)
  • Use test utilities like FakeAccountService when available

2. Test Realistic Scenarios

3. Test Error Handling

4. Verify Side Effects

Running Integration Tests

Troubleshooting

Async Timing Issues

Use waitFor or done callbacks:

Mock Reset Issues

Always reset mocks between tests:

Observable Memory Leaks

Always unsubscribe in tests: