diff --git a/__tests__/utils/helpers.test.ts b/__tests__/utils/helpers.test.ts index 27e3698..a5a1032 100644 --- a/__tests__/utils/helpers.test.ts +++ b/__tests__/utils/helpers.test.ts @@ -74,6 +74,16 @@ describe('Storage Helpers', () => { it('should return null for non-existent key', () => { expect(storage.get('non-existent')).toBeNull(); }); + + it('should return null and log error when localStorage throws', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(); + localStorageMock.getItem.mockImplementationOnce(() => { + throw new Error('Storage error'); + }); + expect(storage.get('test-key')).toBeNull(); + expect(consoleSpy).toHaveBeenCalled(); + consoleSpy.mockRestore(); + }); }); describe('storage.set', () => { @@ -81,6 +91,16 @@ describe('Storage Helpers', () => { storage.set('test-key', 'test-value'); expect(localStorageMock.setItem).toHaveBeenCalledWith('test-key', 'test-value'); }); + + it('should log error when localStorage throws', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(); + localStorageMock.setItem.mockImplementationOnce(() => { + throw new Error('Storage error'); + }); + storage.set('test-key', 'test-value'); + expect(consoleSpy).toHaveBeenCalled(); + consoleSpy.mockRestore(); + }); }); describe('storage.remove', () => { @@ -88,6 +108,16 @@ describe('Storage Helpers', () => { storage.remove('test-key'); expect(localStorageMock.removeItem).toHaveBeenCalledWith('test-key'); }); + + it('should log error when localStorage throws', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(); + localStorageMock.removeItem.mockImplementationOnce(() => { + throw new Error('Storage error'); + }); + storage.remove('test-key'); + expect(consoleSpy).toHaveBeenCalled(); + consoleSpy.mockRestore(); + }); }); describe('storage.clear', () => { @@ -95,6 +125,16 @@ describe('Storage Helpers', () => { storage.clear(); expect(localStorageMock.clear).toHaveBeenCalled(); }); + + it('should log error when localStorage throws', () => { + const consoleSpy = jest.spyOn(console, 'error').mockImplementation(); + localStorageMock.clear.mockImplementationOnce(() => { + throw new Error('Storage error'); + }); + storage.clear(); + expect(consoleSpy).toHaveBeenCalled(); + consoleSpy.mockRestore(); + }); }); });