import { TestBed } from "@angular/core/testing" ; import { LoggerService } from "./logger.service" ; import { CoreModule } from "../../../core/core.module" ; import { SharedModule } from "../../shared.module" ; import { environment } from "../../../../environments/environment" ; describe ( "ConsoleLoggerService" , ( ) => { let service ; beforeEach ( ( done ) => { TestBed . configureTestingModule ( { imports : [ CoreModule , SharedModule ] } ) ; service = TestBed . get ( LoggerService ) ; done ( ) ; } ) ; it ( "should provide console debug" , ( done ) => { environment . logLevel = LoggerService . LEVEL_DEBUG ; const spyDebug = spyOn ( console , "debug" ) ; service . debug ( "hello debug" ) ; expect ( spyDebug ) . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should provide console info" , ( done ) => { environment . logLevel = LoggerService . LEVEL_INFO ; const spyDebug = spyOn ( console , "info" ) ; service . info ( "hello info" ) ; expect ( spyDebug ) . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should provide console warn" , ( done ) => { environment . logLevel = LoggerService . LEVEL_INFO ; const spy = spyOn ( console , "warn" ) ; service . warn ( "hello warn" ) ; expect ( spy ) . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should provide console warn" , ( done ) => { environment . logLevel = LoggerService . LEVEL_WARN ; const spy = spyOn ( console , "warn" ) ; service . warn ( "hello warn" ) ; expect ( spy ) . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should provide console error" , ( done ) => { environment . logLevel = LoggerService . LEVEL_ERROR ; const spy = spyOn ( console , "error" ) ; service . error ( "hello error" ) ; expect ( spy ) . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should not provide log WARN when level is ERROR" , ( done ) => { environment . logLevel = LoggerService . LEVEL_ERROR ; const spy = spyOn ( console , "warn" ) ; service . warn ( "hello warn" ) ; expect ( spy ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should not provide log INFO when level is WARN" , ( done ) => { environment . logLevel = LoggerService . LEVEL_WARN ; const spy = spyOn ( console , "info" ) ; service . info ( "hello info" ) ; expect ( spy ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; it ( "should not provide log DEBUG when level is INFO" , ( done ) => { environment . logLevel = LoggerService . LEVEL_INFO ; const spy = spyOn ( console , "debug" ) ; service . debug ( "hello debug" ) ; expect ( spy ) . not . toHaveBeenCalled ( ) ; done ( ) ; } ) ; } ) ;