Skip to content

Testing

  • Vitest (runner, jsdom environment) + @testing-library/react, @testing-library/jest-dom, @testing-library/user-event.
  • Config: vitest.config.ts (jsdom, src/test/setup.ts, #/* and @/* aliases).
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.

Fenêtre de terminal
npm test # vitest run (once)
npm test -- --watch # watch mode while developing
src/core/permissions/permissions.test.ts
import { describe, expect, it } from 'vitest'
import { hasPermission } from './permissions'
it('grants a present permission', () => {
expect(hasPermission(['FINANCES.VOIR'], 'FINANCES.VOIR')).toBe(true)
})
  • The API client is mocked (authApi.login, authApi.me); the session is a real createAuthSession({ tokenStorage: createMemoryTokenStore() }) or a fake session.
  • We test: field-error mapping (details[].property → error under the input), French message display, the isSubmitting state.
  • ❌ 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.