这是我在打字稿文件中的方法
public get(url: any, options?: object): Observable<any> {
return this.http.get(url.path, merge(options, { params: { metaData: url } }))
.pipe(map((response) => response));
}
以下是用 Angular8 编写的单元测试用例
it('Should call get method', fakeAsync(() => {
service.get(apiUrl, {}).subscribe(response => response);
const req = httpTestingController.match(reqObj => {
return reqObj.url === apiUrl.path;
});
expect(req[0].request.method).toBe('GET');
}));
Sonar 覆盖范围表示 .pipe(map) 中的响应变量未被覆盖。
public get(url: any, options?: object): Observable<any> {
return this.http.get(url.path, merge(options, { params: { metaData: url } }))
.pipe(map(**(response) => response)**);
}
关于涵盖整个方法的任何想法。或者这个方法的更好的单元测试用例。提前致谢!