我正在尝试为角度编写测试,并且遇到了以下错误,例如“无法读取未定义的属性句柄”。不确定如何喜欢它
// data.service.spec.ts
service = new DataService(httpClient, appConfigService,erroService);
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers:
[
{ provide: DataService, useValue: service },
{ provide:AppConfigService, useValue : appConfigService},
{ provide:HttpClient, useValue : httpClient}
]
});
injector = getTestBed();
service= injector.get(DataService);
})
// my test
it('should On Board a new customer',done=>{
var response =service.onboardCustomer(customer);
response.subscribe(res=> {
expect(res.UserID).toBeGreaterThan(0);
})
// DataService.ts
public onboardCustomer(customer: ICustomer): Observable<IOnboardingResponse> {
const model: IOnboardingRequest = {
userID: customer.userrID,
userNumber: customer.userId,
};
return this.http.post<IOnboardingResponse>(`${this.api}/v1/data/users`, model).pipe(
tap(() => {
this.updateCustomerList$().subscribe();
})
);
}