Skip to content

The agent that grows with you

test(desktop): spy on the active localStorage implementation (#82832)

Eugeniusz Gilewski4d4bf0e0e57b
diff --git a/apps/desktop/src/lib/inflight-turn-journal.test.ts b/apps/desktop/src/lib/inflight-turn-journal.test.ts
index 2604c60d7a1..6a0bed4bf22 100644
--- a/apps/desktop/src/lib/inflight-turn-journal.test.ts
+++ b/apps/desktop/src/lib/inflight-turn-journal.test.ts
@@ -105,8 +105,16 @@ describe('persistInFlightTurnState', () => {
})
it('writes only the current session instead of reading and rewriting the aggregate journal', () => {
- const getItem = vi.spyOn(Storage.prototype, 'getItem')
- const setItem = vi.spyOn(Storage.prototype, 'setItem')
+ const localStorage = window.localStorage
+ const storageConstructor = window.Storage
+
+ const spyTarget =
+ typeof storageConstructor === 'function' && localStorage instanceof storageConstructor
+ ? storageConstructor.prototype
+ : localStorage
+
+ const getItem = vi.spyOn(spyTarget, 'getItem')
+ const setItem = vi.spyOn(spyTarget, 'setItem')
persistInFlightTurnState(journalState())
vi.advanceTimersByTime(400)