Skip to content

Commit 694b062

Browse files
msujawsclaude
andcommitted
fix(test): mock navigator.userAgent in API key storage tests
The ApiKeyStorage class uses navigator.userAgent to derive the encryption key. Without mocking this value, tests fail in CI environments where navigator may be undefined or different. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 17f881d commit 694b062

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/lib/storage/api-key-storage.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ApiKeyStorage } from './api-key-storage'
44
describe('ApiKeyStorage', () => {
55
let storage: ApiKeyStorage
66
let localStorageMock: Record<string, string>
7+
const mockUserAgent = 'Mozilla/5.0 (Test) TestBrowser/1.0'
78

89
beforeEach(() => {
910
// Mock localStorage
@@ -26,6 +27,13 @@ describe('ApiKeyStorage', () => {
2627
key: vi.fn(),
2728
}
2829

30+
// Mock navigator.userAgent for consistent encryption key derivation
31+
Object.defineProperty(global, 'navigator', {
32+
value: { userAgent: mockUserAgent },
33+
writable: true,
34+
configurable: true,
35+
})
36+
2937
storage = new ApiKeyStorage()
3038
})
3139

0 commit comments

Comments
 (0)