@@ -2,11 +2,15 @@ import { Logger } from '../../src/utils/logger';
22
33describe ( 'Logger' , ( ) => {
44 let originalConsole : any ;
5- let consoleSpy : jest . SpyInstance ;
5+ let consoleLogSpy : jest . SpyInstance ;
6+ let consoleWarnSpy : jest . SpyInstance ;
7+ let consoleErrorSpy : jest . SpyInstance ;
68
79 beforeAll ( ( ) => {
810 originalConsole = global . console ;
9- consoleSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
11+ consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
12+ consoleWarnSpy = jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
13+ consoleErrorSpy = jest . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } ) ;
1014 } ) ;
1115
1216 afterAll ( ( ) => {
@@ -32,17 +36,17 @@ describe('Logger', () => {
3236 const message = 'Debug message' ;
3337 logger . debug ( message ) ;
3438
35- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
36- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[DEBUG]' ) ) ;
39+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
40+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[DEBUG]' ) ) ;
3741 } ) ;
3842
3943 it ( 'should log message with multiple arguments' , ( ) => {
4044 const logger = new Logger ( ) ;
4145 logger . debug ( 'Object:' , { key : 'value' } , 'Array:' , [ 1 , 2 , 3 ] ) ;
4246
4347 // Check that console.log was called with arguments containing the expected content
44- expect ( consoleSpy ) . toHaveBeenCalled ( ) ;
45- const lastCall = consoleSpy . mock . calls [ consoleSpy . mock . calls . length - 1 ] ;
48+ expect ( consoleLogSpy ) . toHaveBeenCalled ( ) ;
49+ const lastCall = consoleLogSpy . mock . calls [ consoleLogSpy . mock . calls . length - 1 ] ;
4650 const message = lastCall [ 0 ] ;
4751 expect ( message ) . toContain ( 'Object:' ) ;
4852 expect ( message ) . toContain ( 'key' ) ;
@@ -57,15 +61,15 @@ describe('Logger', () => {
5761 const message = 'Info message' ;
5862 logger . info ( message ) ;
5963
60- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
61- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[INFO]' ) ) ;
64+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
65+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[INFO]' ) ) ;
6266 } ) ;
6367
6468 it ( 'should log info message with multiple arguments' , ( ) => {
6569 const logger = new Logger ( 'Test' ) ;
6670 logger . info ( 'User %s logged in with ID %d' , 'Alice' , 123 ) ;
6771
68- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'User %s logged in with ID %d' ) ) ;
72+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'User %s logged in with ID %d' ) ) ;
6973 } ) ;
7074 } ) ;
7175
@@ -75,15 +79,15 @@ describe('Logger', () => {
7579 const message = 'Success message' ;
7680 logger . success ( message ) ;
7781
78- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
79- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[SUCCESS]' ) ) ;
82+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
83+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[SUCCESS]' ) ) ;
8084 } ) ;
8185
8286 it ( 'should log success with checkmark symbol' , ( ) => {
8387 const logger = new Logger ( 'Test' ) ;
8488 logger . success ( 'Operation completed' ) ;
8589
86- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( ' succeed ' ) ) ;
90+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Operation completed ' ) ) ;
8791 } ) ;
8892 } ) ;
8993
@@ -93,8 +97,8 @@ describe('Logger', () => {
9397 const message = 'Warning message' ;
9498 logger . warn ( message ) ;
9599
96- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
97- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[WARN]' ) ) ;
100+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
101+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[WARN]' ) ) ;
98102 } ) ;
99103 } ) ;
100104
@@ -104,17 +108,17 @@ describe('Logger', () => {
104108 const message = 'Error message' ;
105109 logger . error ( message ) ;
106110
107- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
108- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
111+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( message ) ) ;
112+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
109113 } ) ;
110114
111115 it ( 'should log error with stack trace when Error object provided' , ( ) => {
112116 const logger = new Logger ( 'Test' ) ;
113117 const error = new Error ( 'Test error with stack trace' ) ;
114118 logger . error ( error ) ;
115119
116- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
117- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Test error with stack trace' ) ) ;
120+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
121+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Test error with stack trace' ) ) ;
118122 } ) ;
119123 } ) ;
120124
@@ -136,6 +140,7 @@ describe('Logger', () => {
136140 jest . useRealTimers ( ) ;
137141
138142 expect ( elapsed ) . toBeGreaterThanOrEqual ( 1000 ) ;
143+ expect ( consoleLogSpy ) . toHaveBeenCalled ( ) ;
139144 } ) ;
140145 } ) ;
141146
@@ -144,44 +149,44 @@ describe('Logger', () => {
144149 it ( 'should log static debug message' , ( ) => {
145150 Logger . debug ( 'Static debug message' ) ;
146151
147- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[DEBUG]' ) ) ;
148- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static debug message' ) ) ;
152+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[DEBUG]' ) ) ;
153+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static debug message' ) ) ;
149154 } ) ;
150155 } ) ;
151156
152157 describe ( 'Logger.info' , ( ) => {
153158 it ( 'should log static info message' , ( ) => {
154159 Logger . info ( 'Static info message' ) ;
155160
156- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[INFO]' ) ) ;
157- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static info message' ) ) ;
161+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[INFO]' ) ) ;
162+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static info message' ) ) ;
158163 } ) ;
159164 } ) ;
160165
161166 describe ( 'Logger.success' , ( ) => {
162167 it ( 'should log static success message' , ( ) => {
163168 Logger . success ( 'Static success message' ) ;
164169
165- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[SUCCESS]' ) ) ;
166- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static success message' ) ) ;
170+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[SUCCESS]' ) ) ;
171+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static success message' ) ) ;
167172 } ) ;
168173 } ) ;
169174
170175 describe ( 'Logger.warn' , ( ) => {
171176 it ( 'should log static warning message' , ( ) => {
172177 Logger . warn ( 'Static warning message' ) ;
173178
174- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[WARN]' ) ) ;
175- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static warning message' ) ) ;
179+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[WARN]' ) ) ;
180+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static warning message' ) ) ;
176181 } ) ;
177182 } ) ;
178183
179184 describe ( 'Logger.error' , ( ) => {
180185 it ( 'should log static error message' , ( ) => {
181186 Logger . error ( 'Static error message' ) ;
182187
183- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
184- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static error message' ) ) ;
188+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( '[ERROR]' ) ) ;
189+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Static error message' ) ) ;
185190 } ) ;
186191 } ) ;
187192 } ) ;
@@ -192,22 +197,22 @@ describe('Logger', () => {
192197 const obj = { name : 'test' , value : 123 } ;
193198 logger . info ( 'Object:' , obj ) ;
194199
195- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Object:' ) ) ;
200+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Object:' ) ) ;
196201 } ) ;
197202
198203 it ( 'should format arrays properly' , ( ) => {
199204 const logger = new Logger ( 'Test' ) ;
200205 const arr = [ 1 , 2 , 3 ] ;
201206 logger . info ( 'Array:' , arr ) ;
202207
203- expect ( consoleSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Array:' ) ) ;
208+ expect ( consoleLogSpy ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Array:' ) ) ;
204209 } ) ;
205210
206211 it ( 'should handle newline characters in messages' , ( ) => {
207212 const logger = new Logger ( 'Test' ) ;
208213 logger . info ( 'Line 1\nLine 2' ) ;
209214
210- expect ( consoleSpy ) . toHaveBeenCalled ( ) ;
215+ expect ( consoleLogSpy ) . toHaveBeenCalled ( ) ;
211216 } ) ;
212217 } ) ;
213218} ) ;
0 commit comments