jeudi 28 juin 2018

Angular 2 Unit Testing Services with HTTP requests

I am new to testing services with Angular 2 and I am trying to test a service with Http basic requests (Get and GetBYId). - How works my service? : I have a getAllMyProducts method which consumes a REST Api exposed in a Spring boot Backend application .this web api query the products and return products for the current user.(The http request is sent with headers ). - What I want to do? : Now I have to test this GetAll method with Jasmine and I am not sure how to do that especially regarding the current user…

  1. My GetAllMethod in my Service:
getAll(): Observable<Product[]> {
    return this.baseapiService.getAll('/product/userProducts');
    }
  1. my baseapiService that attachs header to the request:
getAll(link){
    this.header = this.createHeader();
    return this.http.get(this.apiurl+link, this.header)
      .map(this.extractData);
  }

Any examlpes or suggestions would be great. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire