import { TestBed , inject } from '@angular/core/testing' ; import { HttpClientTestingModule , HttpTestingController } from '@angular/common/http/testing' ; import { HTTP_INTERCEPTORS , HttpClient } from '@angular/common/http' ; import { environment } from '@env/environment' ; import { ApiPrefixInterceptor } from './api-prefix.interceptor' ; describe ( 'ApiPrefixInterceptor' , ( ) => { let http ; let httpMock ; beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ HttpClientTestingModule ] , providers : [ { provide : HTTP_INTERCEPTORS , useClass : ApiPrefixInterceptor , multi : true } ] } ) ; } ) ; beforeEach ( inject ( [ HttpClient , HttpTestingController ] , ( _http , _httpMock ) => { http = _http ; httpMock = _httpMock ; } ) ) ; afterEach ( ( ) => { httpMock . verify ( ) ; } ) ; it ( 'should prepend environment.serverUrl to the request url' , ( ) => { http . get ( '/toto' ) . subscribe ( ) ; httpMock . expectOne ( { url : environment . serverUrl + '/toto' } ) ; } ) ; it ( 'should not prepend environment.serverUrl to request url' , ( ) => { http . get ( 'hTtPs://domain.com/toto' ) . subscribe ( ) ; httpMock . expectOne ( { url : 'hTtPs://domain.com/toto' } ) ; } ) ; } ) ;