mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-10 18:01:59 +03:00
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>
This commit is contained in:
parent
868a34497b
commit
d528aa9bbb
1 changed files with 30 additions and 0 deletions
30
src/logger.test.ts
Normal file
30
src/logger.test.ts
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Reference in a new issue