When I run the test I get the error TypeError: Cannot read properties of undefined (reading 'controls').
Why I can't access controls in my test file?
My function:
loadData() {
if (this.rootForm.get(['name'])?.value &&
this.rootForm.get(['address'])?.value) {
this.signatureflag = true;
}else {
this.signatureflag = false
}
}
it('load data ',() =>{
let fixture: ComponentFixture<ImportantMattersComponent>;
fixture = TestBed.createComponent(ImportantMattersComponent);
fixture.componentInstance.rootForm.controls.name.setValue('name');
fixture.componentInstance.rootForm.controls.address.setValue('address');
component.loadData();
});
In your test cases
SPEC HAS NO EXPECTATIONSshould not load data when form fields are emptyWorking Example - Stackblitz