运行测试时,出现以下错误: TypeError:无法读取未定义的属性“ subscribe”
我正在将服务注入规范并尝试订阅服务调用
规格:
it('should fetch my client stats', inject(
[ProfileService], (service: ProfileService) => {
const spyC = spyOn(component, 'loadNewAgencyDashboard');
const spyS = spyOn(service, 'fetchMyClientStats');
service.currentProfile.next(mockProfile);
service.fetchMyClientStats().subscribe((response: any) => {
if (service.currentProfile.getValue().role.includes('AGENCY_VIEW')) {
component.agencyView = true;
component.loadNewAgencyDashboard();
} else {
component.loadNewAgencyDashboard();
}
});
fixture.detectChanges();
expect(spyS).toHaveBeenCalledTimes(1);
//expect(component.agencyView).toEqual(true);
//expect(spyC).toHaveBeenCalledTimes(1);
}));
ts:
loadDashboard() {
this.loadingDashboard = true;
this.myName = this.profileService.currentProfile.getValue().fullname;
this.profileService.fetchMyClientStats().subscribe((response: any) => {
// this.AgentData = response.response;
if (this.profileService.currentProfile.getValue().role.includes('AGENCY_VIEW')) {
this.agencyView = true;
this.loadNewAgencyDashboard();
} else {
this.loadNewAgentDashboard();
}
});
}