Я пишу жасминовый тест для проверки вызова службы в angular. Я использовал jasmine.createSpyObj, чтобы шпионить за службой. В настоящее время я получаю сообщение об ошибке
this.agreementsService.getOutstandingAgreements(...).subscribe is not a function
Мой шпион содержит возвращаемую наблюдаемую информацию, не уверенную в чем проблема?
Компонент
public getOutstandingAgreements(Id: number) {
this.agreementsService.getOutstandingAgreements(Id).subscribe((data: AgreementsModel[]) => {
this.myData = data;
if (this.myData) {
this.agreementData = this.myData[0].data;
this.agreementLength = this.myData.length;
this.calculateRemainingDaysLeft(0);
}
});
}
Тестовый файл
describe('AgreementComponent', () => {
let component: AgreementComponent;
let fixture: ComponentFixture<AgreementComponent>;
let mockAgreementsService: AgreementsService;
const mockAgreementsService = jasmine.createSpyObj('AgreementsService', {
getOutstandingAgreements: () => of(['Adam West']) ,
updateAgreement: () => Promise.resolve([])
});
configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [SharedModule, FontAwesomeModule],
declarations: [AgreementComponent, CustomScrollDirective],
providers: [{ provide: UserService, useValue: mockUserService },
{ provide: AgreementsService, useValue: mockAgreementsService }]
});
});
fit('should call getOutstandingAgreements', () => {
const response: AgreementsModel[] = [];
let outStandingAgreementSpy: jasmine.Spy;
let outStandingAgreementServiceSpy: jasmine.Spy;
setupComponent();
outStandingAgreementSpy = spyOn(component, 'getOutstandingAgreements').and.callThrough();
//outStandingAgreementServiceSpy = spyOn(mockAgreementsService, 'getOutstandingAgreements').and.returnValue({ subscribe: () => {} });
component.ngOnInit();
expect(outStandingAgreementSpy).toHaveBeenCalled();
expect(mockAgreementsService.getOutstandingAgreements).toHaveBeenCalled();
//expect(outStandingAgreementServiceSpy).toHaveBeenCalled();
});