/** * ErrorHandler Tests - Core functionality tests * Requirements: 7.1, 7.2, 7.3, 7.4, 7.5, 7.6 */ // Mock globals before importing beforeAll(() => { global.window = { amazonExtEventBus: { emit: jest.fn() } }; global.localStorage = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn() }; global.sessionStorage = { getItem: jest.fn(), setItem: jest.fn(), removeItem: jest.fn() }; }); describe('ErrorHandler', () => { let ErrorHandler; let errorHandler; let handler; beforeAll(async () => { const module = await import('../ErrorHandler.js'); ErrorHandler = module.ErrorHandler; errorHandler = module.errorHandler; }); beforeEach(() => { handler = new ErrorHandler(); jest.clearAllMocks(); jest.spyOn(console, 'error').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {}); jest.spyOn(console, 'info').mockImplementation(() => {}); }); afterEach(() => { jest.restoreAllMocks(); }); describe('Error Classification', () => { test('should classify network errors correctly', () => { const networkError = new Error('Network request failed'); const processed = handler.handleError(networkError, { component: 'test' }); expect(processed.type).toBe(handler.errorTypes.NETWORK); }); test('should classify API key errors correctly', () => { const apiKeyError = new Error('Invalid API key'); const processed = handler.handleError(apiKeyError, { component: 'test' }); expect(processed.type).toBe(handler.errorTypes.API_KEY); }); }); describe('Singleton Instance', () => { test('should export singleton instance', () => { expect(errorHandler).toBeInstanceOf(ErrorHandler); }); }); });