import { TestBed } from '@angular/core/testing' ; import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ; import { HttpClient } from '@angular/common/http' ; import { ErrorInterceptorProvider } from './error.interceptor' ; describe ( 'Error Interceptor' , ( ) => { let httpClient ; let httpMock ; const url = '/api' ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ HttpClientTestingModule ] , } ) ; httpClient = TestBed . inject ( HttpClient ) ; httpMock = TestBed . inject ( HttpTestingController ) ; } ) ; afterEach ( ( ) => httpMock . verify ( ) ) ; it ( 'should not throw error if no error is emitted' , ( ) => { httpClient . get ( url ) . subscribe ( { next : res => expect ( res ) . toBe ( 1 ) , error : err => expect ( err ) . toBeFalsy ( ) } ) ; const req = httpMock . expectOne ( url ) ; expect ( req . request . method ) . toEqual ( 'GET' ) ; req . flush ( 1 ) ; } ) ; } ) ;