Example #1
0
  it('should use cache', () => {
    // Arrange
    let interceptors: HttpInterceptor[];
    const realRequest = http.request;
    spyOn(HttpService.prototype, 'request').and.callFake(function(this: any) {
      interceptors = this.interceptors;
      return realRequest.apply(this, arguments);
    });

    // Act
    const request = http.cache().get('/toto');

    // Assert
    request.subscribe(() => {
      expect(
        interceptors.some(i => i instanceof ApiPrefixInterceptor)
      ).toBeTruthy();
      expect(
        interceptors.some(i => i instanceof ErrorHandlerInterceptor)
      ).toBeTruthy();
      expect(
        interceptors.some(i => i instanceof CacheInterceptor)
      ).toBeTruthy();
    });
    httpMock.expectOne({}).flush({});
  });
Example #2
0
 getRandomQuote(context: RandomQuoteContext): Observable<string> {
   return this.httpClient
     .cache()
     .get(routes.quote(context))
     .pipe(
       map((body: any) => body.value),
       catchError(() => of('Error, could not load joke :-('))
     );
 }
  it('should use cache', () => {
    // Act
    const request = http.cache().get('/toto');

    // Assert
    request.subscribe(() => {
      expect(interceptors.some(i => i instanceof ApiPrefixInterceptor)).toBeTruthy();
      expect(interceptors.some(i => i instanceof ErrorHandlerInterceptor)).toBeTruthy();
      expect(interceptors.some(i => i instanceof CacheInterceptor)).toBeTruthy();
    });
    httpMock.expectOne({}).flush({});
  });