This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| beforeEach(() => { | |
| TestBed.configureTestingModule({ | |
| imports: [ | |
| HttpClientTestingModule | |
| ], | |
| providers: [{ | |
| provide: HTTP_INTERCEPTORS, | |
| useClass: GitHubApiVersionInterceptor, | |
| multi: true, | |
| }] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/')) { |
OlderNewer