Commit 14146c4
committed
[dark-mode] Phase 4.2: ThemeManager unit tests with JSDOM
Add 30 Mocha unit tests for ThemeManager covering all public methods and
edge cases using JSDOM for browser environment simulation.
New file (src/test/modules/themeManager.ts — 30 tests):
- init(): saved preference, system preference, default fallback, idempotent
- getCurrentTheme(): returns current theme, reads from DOM if not set
- setTheme(): applies theme and persists, emits themeChange event,
rejects invalid values, handles localStorage quota errors
- applyTheme(): sets data-theme attribute, updates internal state
- getSystemPreference(): detects dark/light, caches result, handles errors
- hasSavedPreference(): checks localStorage key existence, handles errors
- getSavedPreference(): reads valid values, rejects invalid, handles errors
- emitThemeChange(): dispatches CustomEvent with theme detail
- Invalid value fallback: init() with invalid stored value falls back correctly
Dependencies:
- jsdom (devDependency) for browser environment simulation
Run with: npx ts-mocha src/test/modules/themeManager.ts --timeout 50001 parent e0e1d12 commit 14146c4
5 files changed
Lines changed: 1342 additions & 15 deletions
File tree
- .github/specs/dark-mode/documentation
- src/test/modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
0 commit comments