Я написал тест с жасмином в приложении angular 8 и получаю ошибку. Шпионы должны быть созданы в функции before или spe c. Я попытался обернуть шпионов в beforeEach и тестировать в функции description, но все еще получал ту же ошибку. Что может быть возможным вопросом. Раздел, который я упоминаю, помечен как fdescribe
describe('AgreementComponent', () => {
let component: AgreementComponent;
let fixture: ComponentFixture<AgreementComponent>;
const mockAgreementsService = new Mock<AgreementsService>({
getOutstandingAgreements: () => new Observable<AgreementsModel[]>(),
updateAgreement: () => Promise.resolve([])
}).Object;
configureTestSuite(() => {
TestBed.configureTestingModule({
imports: [SharedModule, FontAwesomeModule],
declarations: [AgreementComponent, CustomScrollDirective],
providers: [{ provide: UserService, useValue: mockUserService },
{ provide: AgreementsService, useValue: mockAgreementsService }]
});
});
function setupComponent() {
fixture = TestBed.createComponent(AgreementComponent);
component = fixture.componentInstance;
}
it('should update when decline Section is called ', () => {
let updateSpy: jasmine.Spy;
setupComponent();
updateSpy = spyOn(component, 'update').withArgs(4).and.returnValue(true);
component.declineSection();
expect(updateSpy).toHaveBeenCalled();
});
fdescribe('Set Values', function () {
const response: AgreementsModel[] = [];
let outStandingAgreementServiceSpy: jasmine.Spy;
let outStandingAgreementSpy: jasmine.Spy;
beforeEach(() => {
outStandingAgreementServiceSpy = spyOn(mockAgreementsService, 'getOutstandingAgreements').and.returnValue(of(response));
outStandingAgreementSpy = spyOn(component, 'getOutstandingAgreements').and.callThrough();
spyOn(component, 'calculateRemainingDaysLeft');
});
it('should call getOutstandingAgreements', () => {
setupComponent();
component.ngOnInit();
expect(outStandingAgreementSpy).toHaveBeenCalled();
expect(outStandingAgreementServiceSpy).toHaveBeenCalled();
});
});
});