I am currently in the process of writing unit tests for a straightforward function that assigns controls to various values.
fillFormAssociazioneVeicolo() {
if (this.aaa) {
setValueControl(
this.aaa.targaTelaio,
this.form.get('targaTelaio')
);
setValueControl(
this.aaa.tipoVeicolo,
this.form.get('tipoVeicolo')
);
setValueControl(
this.aaa.tipoVeicolo?.descrizione,
this.form.get('descTipoVeicolo')
);
setValueControl(
this.aaa.nomeCognome,
this.form.get('nomeCognome')
);
setValueControl(
this.aaa.codiceFiscale,
this.form.get('codiceFiscale')
);
}
This is the purpose of the setValueControl function:
export function setValueControl(
value: any,
control: AbstractControl | null,
disable: boolean = true
) {
if (control) {
control.setValue(value);
if (disable) disableControl(control);
}
}
I attempted the following approach, however it did not yield the expected result:
it('can fillFormAssociazioneVeicolo', () => {
component.riempiFormAssociazioneVeicolo();
expect(setValueControl(component.associazioneVeicolo?.tipoVeicolo,component.form.get('tipoVeicolo')));
});