import { databaseFactory } from './database' import { LocalStorage } from './local-storage' import { MemoryStorage } from './memory-storage' describe('databaseFactory', () => { beforeEach(() => { // restore the spy created with spyOn jest.restoreAllMocks() }) it('should return a LocalStorage instance if local storage is enabled', () => { jest.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {}) jest.spyOn(Storage.prototype, 'removeItem').mockImplementation(() => {}) const result = databaseFactory() expect(result).toBeInstanceOf(LocalStorage) }) it('should return a MemoryStorage instance if local storage is not enabled', () => { jest.spyOn(Storage.prototype, 'setItem').mockImplementation(() => { throw new Error('Local storage not available') }) jest.spyOn(Storage.prototype, 'removeItem').mockImplementation(() => {}) const result = databaseFactory() expect(result).toBeInstanceOf(MemoryStorage) }) })