import { TestBed } from '@angular/core/testing' ; import { Themes , ThemeService } from './theme.service' ; describe ( 'ThemeService' , ( ) => { let themeService ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { providers : [ ThemeService ] } ) ; themeService = TestBed . inject ( ThemeService ) ; } ) ; describe ( 'dark() method' , ( ) => { it ( 'should change the theme to dark' , done => { themeService . dark ( ) ; themeService . theme$ . subscribe ( theme => { expect ( theme ) . toBe ( Themes . Dark ) ; expect ( theme ) . not . toBe ( Themes . Light ) ; done ( ) ; } ) ; } ) ; } ) ; describe ( 'light() method' , ( ) => { it ( 'should change the theme to light' , done => { themeService . light ( ) ; themeService . theme$ . subscribe ( theme => { expect ( theme ) . toBe ( Themes . Light ) ; expect ( theme ) . not . toBe ( Themes . Dark ) ; done ( ) ; } ) ; } ) ; } ) ; describe ( 'toggle() method' , ( ) => { it ( 'should toggle the theme between light and dark' , done => { jest . spyOn ( themeService , 'activeTheme' ) . mockReturnValue ( Themes . Dark ) ; themeService . toggle ( ) ; themeService . theme$ . subscribe ( theme => { expect ( theme ) . toBe ( Themes . Light ) ; expect ( theme ) . not . toBe ( Themes . Dark ) ; done ( ) ; } ) ; } ) ; } ) ; } ) ;