import { getLocalStorage } from "."; import { MemoryStorage } from "./basic"; import { BrowserLocalStorage } from "./browser"; const localStorage = (window as any).localStorage; describe(getLocalStorage, () => { it("returns the best storage available", () => { const mockWarn = jest.spyOn(console, "warn").mockImplementation(); let storage = getLocalStorage(); expect(storage).toBeInstanceOf(BrowserLocalStorage); expect(mockWarn).not.toHaveBeenCalled(); delete (window as any)["localStorage"]; storage = getLocalStorage(); expect(storage).toBeInstanceOf(MemoryStorage); expect(mockWarn).toHaveBeenCalledWith("No persistent storage available, using in-memory volatile storage"); }); }); afterEach(() => { (window as any).localStorage = localStorage; });