I have to test if some controls are enabled.
ngOnChanges(): void {
this.form.get('menuVisibility').valueChanges.subscribe((visible: boolean) => {
['userIdVisibility', 'userOptionsVisibility', 'languageVisibility'].forEach((controlName) => {
if (visible) {
this.form.controls[controlName].enable();
} else {
this.form.controls[controlName].disable();
}
});
});
}
I wrote this SPEC:
it('should dispatch action for valueChanges', fakeAsync(() => {
component.form.get('menuVisibility').setValue(true);
component.form.get('menuVisibility').updateValueAndValidity({ emitEvent: true });
component.ngOnChanges();
tick();
expect(component.form.get('userIdVisibility').enabled).toBeTruthy();
expect(component.form.get('userOptionsVisibility').enabled).toBeTruthy();
expect(component.form.get('languageVisibility').enabled).toBeTruthy();
}));
But the test never enters in the forEach block.