我正在服务中导入并使用HttpClient
,如下所示:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root',
})
export class MyService {
constructor(private http: HttpClient) { }
getData() {
return this.http.get("url...");
}
}
然而,当我为我的unit tests运行ng test
时,当这些测试使用该服务时,我得到了错误:
Error: StaticInjectorError(DynamicTestModule)[HttpClient]:
StaticInjectorError(Platform: core)[HttpClient]:
NullInjectorError: No provider for HttpClient!
Angular 6 documentation on HTTP只是说要做我上面做过的事.