import { TestBed } from '@angular/core/testing' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { environment } from '../environments/environment' ; import { AppErrorHandler } from './app-error-handler' ; describe ( AppErrorHandler . name , ( ) => { let service ; let snackbarSpy ; let consoleSpy ; beforeEach ( ( ) => { snackbarSpy = jasmine . createSpyObj ( 'MatSnackBar' , [ 'open' ] ) ; consoleSpy = spyOn ( console , 'log' ) ; TestBed . configureTestingModule ( { providers : [ AppErrorHandler , { provide : MatSnackBar , useValue : snackbarSpy } ] } ) ; service = TestBed . inject ( AppErrorHandler ) ; } ) ; it ( 'should be created' , ( ) => { expect ( service ) . toBeTruthy ( ) ; } ) ; it ( 'should handle an error' , ( ) => { const error = { message : 'Fake error' } as Error ; service . handleError ( error ) ; expect ( snackbarSpy . open ) . toHaveBeenCalledWith ( environment . settings . appErrorPrefix + 'Fake error' ) ; expect ( consoleSpy ) . toHaveBeenCalledWith ( error ) ; } ) ; } ) ;