/** * Tests for Logger Utility * FE-TEST-004: Test logger utility functions */ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; import { logger } from './logger'; describe('logger utilities', () => { let consoleDebugSpy: ReturnType; let consoleInfoSpy: ReturnType; let consoleWarnSpy: ReturnType; let consoleErrorSpy: ReturnType; beforeEach(() => { consoleDebugSpy = vi.spyOn(console, 'debug').mockImplementation(() => {}); consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}); consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); }); afterEach(() => { vi.restoreAllMocks(); }); describe('logger.debug', () => { it('should log in development mode', () => { // In test environment, DEV is typically true logger.debug('test message'); // Just verify it doesn't throw - actual behavior depends on import.meta.env.DEV expect(typeof logger.debug).toBe('function'); }); }); describe('logger.info', () => { it('should log in development mode', () => { // In test environment, DEV is typically true logger.info('test message'); // Just verify it doesn't throw - actual behavior depends on import.meta.env.DEV expect(typeof logger.info).toBe('function'); }); }); describe('logger.warn', () => { it('should always log warnings', () => { const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); logger.warn('test warning'); // In dev mode, logger uses console.log with formatted prefix expect(consoleLogSpy).toHaveBeenCalledWith( expect.stringContaining('[WARN] test warning'), ); consoleLogSpy.mockRestore(); }); }); describe('logger.error', () => { it('should always log errors', () => { const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); logger.error('test error'); // In dev mode, logger uses console.log with formatted prefix expect(consoleLogSpy).toHaveBeenCalledWith( expect.stringContaining('[ERROR] test error'), ); consoleLogSpy.mockRestore(); }); }); });