// src/services/logger.client.test.ts import { describe, it, expect, vi, afterEach } from 'vitest'; // IMPORTANT: Unmock the module to ensure we test the REAL implementation, // not an auto-mocked version that doesn't actually call console methods. vi.unmock('./logger.client'); import { logger } from './logger.client'; console.log('Logger implementation:', logger); describe('Client Logger', () => { afterEach(() => { // Restore all spies vi.restoreAllMocks(); }); it('logger.info calls console.log with [INFO] prefix', () => { // Access globalThis.console to ensure we spy on the environment's actual console const spy = vi.spyOn(globalThis.console, 'log').mockImplementation(() => {}); const message = 'test info'; const data = { foo: 'bar' }; logger.info(message, data); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(`[INFO] ${message}`, data); }); it('logger.warn calls console.warn with [WARN] prefix', () => { const spy = vi.spyOn(globalThis.console, 'warn').mockImplementation(() => {}); const message = 'test warn'; logger.warn(message); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(`[WARN] ${message}`); }); it('logger.error calls console.error with [ERROR] prefix', () => { const spy = vi.spyOn(globalThis.console, 'error').mockImplementation(() => {}); const message = 'test error'; const err = new Error('fail'); logger.error(message, err); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(`[ERROR] ${message}`, err); }); it('logger.debug calls console.debug with [DEBUG] prefix', () => { const spy = vi.spyOn(globalThis.console, 'debug').mockImplementation(() => {}); const message = 'test debug'; logger.debug(message); expect(spy).toHaveBeenCalledTimes(1); expect(spy).toHaveBeenCalledWith(`[DEBUG] ${message}`); }); });