Angular如何测试“ new Subject <void>()”

时间:2019-05-06 15:13:19

标签: angular karma-jasmine

我是Angular单元测试的新手。我在服务中使用了new Subject<void>(),但无法为其编写茉莉花代码。

service.ts文件

public _refreshNeeded = new Subject<void>();

get refreshNeeded() {
  console.log(this._refreshNeeded)
  return this._refreshNeeded;
}

getDetails() {
  return  this.httpClient.get<Data[]>(`${this.API_URL}`);
}

postDetails(user: Data, seqcode: any): Observable<Data[]>{
  return this.httpClient.post<Data[]>(`${this.API_URL}`, user).pipe(tap(()=> {
      this._refreshNeeded.next()
  }));
}

component.ts文件

ngOnInit() {
  this.corpTrustService._refreshNeeded.subscribe(() => {
    this.getDetails();
  });

  this.getDetails();
}

0 个答案:

没有答案