forked from mfittko/geo-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.test.ts
More file actions
53 lines (46 loc) · 1.73 KB
/
logging.test.ts
File metadata and controls
53 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { logger, isVerboseLoggingEnabled } from '@/utils/logging';
// Mock console methods
const mockConsoleLog = jest.spyOn(console, 'log').mockImplementation(() => {
// Default implementation - will be overridden by provider
});
const mockConsoleWarn = jest.spyOn(console, 'warn').mockImplementation(() => {
// Default implementation - will be overridden by provider
});
const mockConsoleError = jest.spyOn(console, 'error').mockImplementation(() => {
// Default implementation - will be overridden by provider
});
describe('logging utility', () => {
beforeEach(() => {
jest.clearAllMocks();
});
afterAll(() => {
mockConsoleLog.mockRestore();
mockConsoleWarn.mockRestore();
mockConsoleError.mockRestore();
});
describe('logger', () => {
it('should log debug messages when verbose logging is enabled', () => {
if (isVerboseLoggingEnabled()) {
logger.debug('test debug message');
expect(mockConsoleLog).toHaveBeenCalledWith('[DEBUG]', 'test debug message');
} else {
logger.debug('test debug message');
expect(mockConsoleLog).not.toHaveBeenCalled();
}
});
it('should always log error messages', () => {
logger.error('test error message');
expect(mockConsoleError).toHaveBeenCalledWith('[ERROR]', 'test error message');
});
it('should log warning messages when enabled', () => {
logger.warn('test warning message');
// Warnings should be logged in most environments
expect(mockConsoleWarn).toHaveBeenCalledWith('[WARN]', 'test warning message');
});
});
describe('isVerboseLoggingEnabled', () => {
it('should return a boolean', () => {
expect(typeof isVerboseLoggingEnabled()).toBe('boolean');
});
});
});