| name | integration-testing |
| description | Guidelines for cross-layer testing (Hooks + UI + Services) using real logic and MSW for network interception. |
Integration Testing Skill
This skill defines how to implement and organize integration tests that validate the interaction between services, custom hooks, and UI components.
Core Principle: "Real Logic, Mocked Network"
Unlike unit tests that mock functions, integration tests in FinanzApp use:
- Real Services: Calls to
src/services/ are executed.
- Real Hooks: Custom hooks in
src/hooks/ manage the actual state.
- MSW (Mock Service Worker): Intercepts Axios requests at the network level to provide controlled JSON responses.
Organization
All integration tests MUST be located in the global integration directory:
- Path:
tests/integration/[module]/[Feature].test.tsx
Guidelines
- Scope: Test full business flows (e.g., Login -> Store Token -> Redirect).
- No Manual Mocks: Avoid
vi.mock() for internal services or hooks; test their real interaction.
- MSW Handlers: Define shared handlers in
tests/msw/handlers.ts and use server.use() for test-specific overrides.
- DOM Validation: Use React Testing Library to verify that the UI updates correctly based on the real hook/service state.
- Clean State: Ensure
localStorage, sessionStorage, and MSW handlers are cleared between tests.
Example
import { render, screen, fireEvent } from '@/test/test-utils';
import { server } from '@/test/msw/server';
import { http, HttpResponse } from 'msw';
it('should complete the login flow successfully', async () => {
server.use(
http.post('*/api/auth/login', () => {
return HttpResponse.json({ token: 'fake_jwt', user: { name: 'Agus' } });
})
);
render(<LoginPage />);
fireEvent.change(screen.getByLabelText(/email/i), { target: { value: 'test@example.com' } });
fireEvent.click(screen.getByRole('button', { name: /ingresar/i }));
expect(await screen.findByText(/hola, agus/i)).toBeInTheDocument();
});