Skip to content

Instantly share code, notes, and snippets.

View IAfanasovMob's full-sized avatar

Igor Afanasov IAfanasovMob

View GitHub Profile
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: GitHubApiVersionInterceptor,
multi: true,
}]
it(`should add Accept header with value 'application/vnd.github.v3.star+json'
when requested https://api.github.com/*`, () => {
client.get('https://api.github.com/anything').subscribe();
const requests = httpMock.match({ method: 'get' });
expect(requests[0].request.headers.get('Accept'))
.toEqual('application/vnd.github.v3.star+json');
});
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class GitHubApiVersionInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (req.url.startsWith('https://api.github.com/')) {