# Unit Test Fix Summary

## Problem
The unit tests for `apps/web` were failing due to three main issues:
1. **E2E Test Conflict**: Playwright E2E tests (`*.e2e.spec.ts`) were being included in the Vitest run, causing environment conflicts.
2. **Mocking Failures**: `vi.mock` calls using path aliases (e.g., `@/services/api`) were not correctly intercepting imports, causing tests to hit the real network (`ECONNREFUSED`).
3. **Hoisting Issues**: Variables used in `vi.mock` factories were not hoisted, causing `ReferenceError`.
4. **Noise**: Tests from `node_modules` (Quasar, Zod) were being executed.

## Solution

### 1. Configuration (`vitest.config.ts`)
- Updated `exclude` pattern to strictly ignore E2E tests and `node_modules`.
```typescript
exclude: ['**/node_modules/**', '**/dist/**', '**/*.e2e.spec.ts']
```

### 2. Mocking Strategy
- Switched from **Alias Imports** to **Relative Imports** in `vi.mock` calls. This ensures Vitest correctly resolves and mocks the module identity.
- **Before**: `vi.mock('@/services/api', ...)`
- **After**: `vi.mock('../../../services/api', ...)`

### 3. Hoisting
- Used `vi.hoisted()` to define mock variables outside the test suite, ensuring they are available when `vi.mock` is hoisted.

### 4. Logic Fixes
- Updated `aiStore.spec.ts` to use `expect.objectContaining` for flexible argument matching.

## Results
- **All 20 Test Files Passed**.
- **174 Tests Passed**.
- Execution time is fast (~1.7s).
- No network calls are leaking.

## Verification
Run the tests with:
```bash
pnpm --filter @my-roadtrip/web test:unit
```
