Skip to content

Commit 14146c4

Browse files
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 5000
1 parent e0e1d12 commit 14146c4

5 files changed

Lines changed: 1342 additions & 15 deletions

File tree

.github/specs/dark-mode/documentation/progress-report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
| Phase | Description | Status |
3434
|-------|-------------|--------|
3535
| **4.1** | Code review & cleanup | ✅ Done |
36-
| **4.2** | Unit tests for ThemeManager | Not Started |
36+
| **4.2** | Unit tests for ThemeManager | ✅ Done |
3737
| **4.3** | Developer documentation | Not Started |
3838
| **4.4** | Update project documentation (README, DEVELOPMENT.md) | Not Started |
3939
| **5.1** | Prepare for merge (rebase, PR) | Not Started |

0 commit comments

Comments
 (0)