Testing
Installed tools
Section titled “Installed tools”- Vitest (runner,
jsdomenvironment) + @testing-library/react, @testing-library/jest-dom, @testing-library/user-event. - Config:
vitest.config.ts(jsdom,src/test/setup.ts,#/*and@/*aliases).
Test pyramid
Section titled “Test pyramid”| Level | Examples | Where |
|---|---|---|
| Unit (pure functions) | core/permissions (hasPermission), core/api/api-error (normalization), core/query/query-keys |
*.test.ts next to the file |
| Component integration | login form (mocked API client) | src/routes/login.test.tsx |
| E2E / smoke | real login against the dev backend | manual (npm run dev + devtools) |
The foundation targets the first two levels; features add their own tests following the same model.
Writing a test
Section titled “Writing a test”npm test # vitest run (once)npm test -- --watch # watch mode while developingimport { describe, expect, it } from 'vitest'import { hasPermission } from './permissions'
it('grants a present permission', () => { expect(hasPermission(['FINANCES.VOIR'], 'FINANCES.VOIR')).toBe(true)})UI tests (login)
Section titled “UI tests (login)”- The API client is mocked (
authApi.login,authApi.me); the session is a realcreateAuthSession({ tokenStorage: createMemoryTokenStore() })or a fake session. - We test: field-error mapping (
details[].property→ error under the input), French message display, theisSubmittingstate.
Don’ts
Section titled “Don’ts”- ❌ Test implementation details (CSS class snapshots, internals).
- ❌ Real network tests in the Vitest suite (slow, env-dependent).
- ❌ Ignore a failing test — fix it or remove it with justification.
