|
| 1 | +# 🧪 Teststrategie für BestNote |
| 2 | + |
| 3 | +Dieses Projekt verwendet [Vitest](https://vitest.dev/) und [Vue Test Utils](https://test-utils.vuejs.org/) für Unit- und Integrationstests. |
| 4 | + |
| 5 | +## 📦 Struktur |
| 6 | + |
| 7 | +- Testdateien liegen unter `tests/` |
| 8 | +- Dateinamen: `*.test.ts` |
| 9 | +- Direktiven-Tests: `tests/directives/` |
| 10 | +- Services-Tests: `tests/services/` |
| 11 | + |
| 12 | +## 🧩 Pinia-Test-Setup |
| 13 | + |
| 14 | +Für Tests mit Pinia-Stores: |
| 15 | + |
| 16 | +- Nutze `createTestingPinia()` aus `@pinia/testing` |
| 17 | +- Stelle sicher, dass Directive und Test dieselbe Store-Instanz verwenden |
| 18 | +- Ändere Store-Werte mit `$patch()` statt direkter Zuweisung |
| 19 | + |
| 20 | +Beispiel: |
| 21 | + |
| 22 | +```ts |
| 23 | +import { createTestingPinia } from '@pinia/testing' |
| 24 | +import { setActivePinia } from 'pinia' |
| 25 | +import { useUserStore } from '@/store/user' |
| 26 | + |
| 27 | +const pinia = createTestingPinia() |
| 28 | +setActivePinia(pinia) |
| 29 | +const userStore = useUserStore() |
| 30 | +userStore.$patch({ primaryRole: 'admin' }) |
| 31 | +``` |
| 32 | + |
| 33 | +## 🧪 Direktiven testen |
| 34 | + |
| 35 | +- Nutze `shallowMount()` mit einer kleinen Testkomponente |
| 36 | +- Verwende `nextTick()` und ggf. `setTimeout(0)` für reaktive DOM-Updates |
| 37 | +- Prüfe Sichtbarkeit über `el.style.display` ('' oder 'none') statt `isVisible()` |
| 38 | + |
| 39 | +Beispiel-Assertion: |
| 40 | + |
| 41 | +```ts |
| 42 | +expect(button.style.display).toBe('none') |
| 43 | +``` |
| 44 | + |
| 45 | +## 🧪 Tests ausführen |
| 46 | + |
| 47 | +```bash |
| 48 | +npm run test |
| 49 | +``` |
| 50 | + |
| 51 | +## 📊 Coverage erzeugen |
| 52 | + |
| 53 | +```bash |
| 54 | +npm run test -- --coverage |
| 55 | +``` |
| 56 | + |
| 57 | +Ergebnis: `coverage/index.html` im Browser öffnen |
| 58 | + |
| 59 | +## 🛠 Erweiterungen |
| 60 | + |
| 61 | +- Snapshot-Tests mit `toMatchSnapshot()` |
| 62 | +- Integrationstests mit echten Komponenten |
| 63 | +- Teststrategie für die Rollenmatrix (`src/services/PermissionService.ts`) |
0 commit comments