From d528aa9bbb49c491b8d62bfa386e1a1965d4eefa Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:35:18 +0300 Subject: [PATCH] test: add unit tests for logger utility (#96) Adds a test file `src/logger.test.ts` to verify that `logger.info`, `logger.warn`, and `logger.error` correctly call the underlying console methods with the passed arguments. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- src/logger.test.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/logger.test.ts diff --git a/src/logger.test.ts b/src/logger.test.ts new file mode 100644 index 0000000..bf2874e --- /dev/null +++ b/src/logger.test.ts @@ -0,0 +1,30 @@ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { logger } from './logger'; + +describe('logger', () => { + beforeEach(() => { + vi.spyOn(console, 'info').mockImplementation(() => {}); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + vi.spyOn(console, 'error').mockImplementation(() => {}); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('should call console.info with correct arguments', () => { + logger.info('test info', { key: 'value' }); + expect(console.info).toHaveBeenCalledWith('test info', { key: 'value' }); + }); + + it('should call console.warn with correct arguments', () => { + logger.warn('test warn', 42); + expect(console.warn).toHaveBeenCalledWith('test warn', 42); + }); + + it('should call console.error with correct arguments', () => { + const error = new Error('test error'); + logger.error('test error message', error); + expect(console.error).toHaveBeenCalledWith('test error message', error); + }); +});