@@ -213,6 +213,8 @@ describe('<Logging>', function() {
213213 } )
214214
215215 it ( 'doesnt throw an error if the message is not a string' , async ( ) => {
216+ prepareMockRequest ( { } )
217+
216218 async function check ( method ) {
217219 expect ( ( ) => logger [ method ] ( 0 ) ) . to . not . throw ( )
218220 expect ( ( ) => logger [ method ] ( 123 ) ) . to . not . throw ( )
@@ -231,6 +233,8 @@ describe('<Logging>', function() {
231233 await check ( 'error' )
232234 await check ( 'fatal' )
233235 await check ( 'trace' )
236+
237+ await Backendless . Logging . flush ( )
234238 } )
235239
236240 it ( 'converts non-string values to strings' , async ( ) => {
@@ -324,8 +328,16 @@ describe('<Logging>', function() {
324328 } )
325329
326330 it ( 'should try to send next time if it was failed' , async ( ) => {
331+ // eslint-disable-next-line no-console
332+ const _nativeConsoleError = console . error
333+
334+ // eslint-disable-next-line no-console
335+ const spyConsoleError = console . error = chai . spy ( )
336+
337+ const error = new Error ( 'Test Error' )
338+
327339 const req1 = prepareMockRequest ( ( ) => {
328- throw new Error ( 'Test Error' )
340+ throw error
329341 } )
330342
331343 const req2 = prepareMockRequest ( )
@@ -357,14 +369,30 @@ describe('<Logging>', function() {
357369 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 2' , timestamp : req1 . body [ 1 ] . timestamp } ,
358370 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 3' , timestamp : req2 . body [ 2 ] . timestamp }
359371 ] )
372+
373+ expect ( spyConsoleError ) . to . have . been . called . exactly ( 1 )
374+
375+ expect ( spyConsoleError ) . on . nth ( 1 ) . be . called . with ( 'Could not flush log messages immediately: ' , error )
376+
377+ // eslint-disable-next-line no-console
378+ console . error = _nativeConsoleError
360379 } )
361380
362381 it ( 'should keep messages if they were not sent #1' , async ( ) => {
382+ // eslint-disable-next-line no-console
383+ const _nativeConsoleError = console . error
384+
385+ // eslint-disable-next-line no-console
386+ const spyConsoleError = console . error = chai . spy ( )
387+
388+ const error1 = new Error ( 'Test Error1' )
389+ const error2 = new Error ( 'Test Error2' )
390+
363391 const req1 = prepareMockRequest ( ( ) => {
364- throw new Error ( 'Test Error1' )
392+ throw error1
365393 } )
366394 const req2 = prepareMockRequest ( ( ) => {
367- throw new Error ( 'Test Error2' )
395+ throw error2
368396 } )
369397 const req3 = prepareMockRequest ( )
370398
@@ -406,14 +434,31 @@ describe('<Logging>', function() {
406434 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 5' , timestamp : req3 . body [ 4 ] . timestamp } ,
407435 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 6' , timestamp : req3 . body [ 5 ] . timestamp } ,
408436 ] )
437+
438+ expect ( spyConsoleError ) . to . have . been . called . exactly ( 2 )
439+
440+ expect ( spyConsoleError ) . on . nth ( 1 ) . be . called . with ( 'Could not flush log messages immediately: ' , error1 )
441+ expect ( spyConsoleError ) . on . nth ( 2 ) . be . called . with ( 'Could not flush log messages immediately: ' , error2 )
442+
443+ // eslint-disable-next-line no-console
444+ console . error = _nativeConsoleError
409445 } )
410446
411447 it ( 'should keep messages if they were not sent #2' , async ( ) => {
448+ // eslint-disable-next-line no-console
449+ const _nativeConsoleError = console . error
450+
451+ // eslint-disable-next-line no-console
452+ const spyConsoleError = console . error = chai . spy ( )
453+
454+ const error1 = new Error ( 'Test Error1' )
455+ const error2 = new Error ( 'Test Error2' )
456+
412457 const req1 = prepareMockRequest ( ( ) => {
413- throw new Error ( 'Test Error1' )
458+ throw error1
414459 } )
415460 const req2 = prepareMockRequest ( ( ) => {
416- throw new Error ( 'Test Error2' )
461+ throw error2
417462 } )
418463 const req3 = prepareMockRequest ( )
419464
@@ -461,6 +506,14 @@ describe('<Logging>', function() {
461506 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 7' , timestamp : req3 . body [ 5 ] . timestamp } ,
462507 { 'log-level' : 'DEBUG' , 'logger' : loggerName , 'message' : 'debug message - 8' , timestamp : req3 . body [ 6 ] . timestamp } ,
463508 ] )
509+
510+ expect ( spyConsoleError ) . to . have . been . called . exactly ( 2 )
511+
512+ expect ( spyConsoleError ) . on . nth ( 1 ) . be . called . with ( 'Could not flush log messages immediately: ' , error1 )
513+ expect ( spyConsoleError ) . on . nth ( 2 ) . be . called . with ( 'Could not flush log messages immediately: ' , error2 )
514+
515+ // eslint-disable-next-line no-console
516+ console . error = _nativeConsoleError
464517 } )
465518
466519 it ( 'should send 100 messages by default' , async ( ) => {
0 commit comments