Skip to content

Commit eec208f

Browse files
msujawsclaude
andcommitted
fix(test): use vi.stubGlobal for consistent mocking in CI
Replace Object.defineProperty and direct global assignment with vi.stubGlobal() for localStorage and navigator mocks. This ensures consistent behavior across different environments (macOS vs Linux/CI). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e1e1fa8 commit eec208f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('ApiKeyStorage', () => {
1010
// Mock localStorage
1111
localStorageMock = {}
1212

13-
global.localStorage = {
13+
vi.stubGlobal('localStorage', {
1414
// eslint-disable-next-line unicorn/no-null
1515
getItem: vi.fn((key: string) => localStorageMock[key] ?? null), // null is correct for localStorage API
1616
setItem: vi.fn((key: string, value: string) => {
@@ -25,20 +25,17 @@ describe('ApiKeyStorage', () => {
2525
}),
2626
length: 0,
2727
key: vi.fn(),
28-
}
28+
})
2929

3030
// Mock navigator.userAgent for consistent encryption key derivation
31-
Object.defineProperty(global, 'navigator', {
32-
value: { userAgent: mockUserAgent },
33-
writable: true,
34-
configurable: true,
35-
})
31+
vi.stubGlobal('navigator', { userAgent: mockUserAgent })
3632

3733
storage = new ApiKeyStorage()
3834
})
3935

4036
afterEach(() => {
4137
vi.restoreAllMocks()
38+
vi.unstubAllGlobals()
4239
})
4340

4441
describe('saveApiKey', () => {

0 commit comments

Comments
 (0)