Я написал тест на жасмине для моего углового приложения, которое не работает, но реальная функциональность работает абсолютно нормально.Я также вызываю fixture.DetectChanges (), но не уверен, в чем может быть проблема.Я получаю сообщение об ошибке
TypeError: Невозможно прочитать свойство 'maxSize' из неопределенного в DomicileSelectionComponent.isMinValid (webpack: /// C: /vstsprojects/Risk.Analytics.Captives/Clientside/captives/src/ app / pages / осуществимость / недостатки / домицилирование-выбор / domicile-selection.component.ts?: 88: 52)
Почему ошибка возникает только для maxSize, а не minSize?
TestComponent
describe('DomicileSelectionComponent', () => {
let comp: DomicileSelectionComponent;
let fixture: ComponentFixture<DomicileSelectionComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
TooltipModule.forRoot(),
FormsModule,
TranslateModule.forRoot({
loader: { provide: TranslateLoader, useClass: TranslateFakeLoader }
})
],
providers: [
{ provide: BsModalRef, useClass: BsModalRefStub },
{ provide: BackendProxy.ReferenceProxy, useClass: ReferenceProxyStub },
{ provide: RunService, useValue: runServiceStub }
],
declarations: [DomicileSelectionComponent, YesNoPipe, CLICK_INPUT_DIRECTIVE, ShortNumberFormatPipe]
});
});
beforeEach(() => {
spyOn(BsModalRefStub.prototype, 'hide').and.callThrough();
fixture = TestBed.createComponent(DomicileSelectionComponent);
comp = fixture.componentInstance;
comp.domicileInfo = domicileInformationDataResult.data;
fixture.detectChanges();
});
fit('should return true because the index of the item is zero and min is less than max', () => {
comp.domicileInfo.taxAssesment.items = [{ minSize: 30000000, maxSize: 40000000, values: [0.02, 0.02]}];
fixture.detectChanges();
console.log(comp.domicileInfo.taxAssesment.items);
let isMin: boolean = comp.isMinValid(comp.domicileInfo.taxAssesment.items, 0);
expect(isMin).toBe(true);
});
});
Основной компонент
isMinValid(currentItem: any, index: number) {
if (index === 0 && (+currentItem.minSize <= +currentItem.maxSize)) {
return !this._isMinValid;
}
else if ( index === 0 && +currentItem.minSize >= +currentItem.maxSize) {
return this._isMinValid;
}
let previousItem = this.domicileInfo.taxAssesment.items[index - 1];
if (+currentItem.minSize !== +previousItem.maxSize) {
return this._isMinValid;
}
return !this._isMinValid;
}