带有HTTP请求的Angular 2单元测试服务

时间:2018-06-28 11:27:39

标签: testing jasmine angular2-services

我刚开始使用Angular 2测试服务,并且尝试使用Http基本请求(Get和GetBYId)测试服务。 -我的服务如何运作? :我有一个getAllMyProducts方法,该方法使用Spring Boot后端应用程序中公开的REST Api。此Web api查询产品并返回当前用户的产品。(HTTP请求带有标头发送)。 - 我想做的事? :现在,我必须使用Jasmine测试此GetAll方法,并且我不确定如何执行此操作,尤其是对于当前用户……

  1. 我在服务中的GetAllMethod:

getAll(): Observable<Product[]> {
    return this.baseapiService.getAll('/product/userProducts');
    }

  1. 将标头附加到请求的我的baseapiService:

getAll(link){
    this.header = this.createHeader();
    return this.http.get(this.apiurl+link, this.header)
      .map(this.extractData);
  }

任何评论或建议都会很棒。预先感谢

0 个答案:

没有答案