Skip to content

Commit 08621f9

Browse files
committed
test: check if formcontrol is defined before using its value #1571
1 parent 651399f commit 08621f9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

frontend/src/app/components/key-result-type/key-result-type.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ describe('KeyResultTypeComponent', () => {
215215
KeyResultMetricField.STRETCH_GOAL]])('Should call calculateValueForField with the correct enum', (values: MetricValue, changed: KeyResultMetricField, result: KeyResultMetricField) => {
216216
const spyInstance = jest.spyOn(component, 'calculateValueForField');
217217

218-
component.calculateValueAfterChanged(values, changed);
218+
component.calculateValueAfterChanged(values, changed, component.keyResultForm);
219219
expect(spyInstance)
220-
.toHaveBeenCalledWith(values, result);
220+
.toHaveBeenCalledWith(values, result, component.keyResultForm);
221221
});
222222

223223
it.each([
@@ -309,7 +309,7 @@ describe('KeyResultTypeComponent', () => {
309309
KeyResultMetricField.STRETCH_GOAL,
310310
{ stretchGoal: 5 }]
311311
])('calculateValueForField should calculate correct', (values: MetricValue, targetField: KeyResultMetricField, result: any) => {
312-
expect(component.calculateValueForField(values, targetField))
312+
expect(component.calculateValueForField(values, targetField, component.keyResultForm))
313313
.toEqual(result);
314314
});
315315

frontend/src/app/components/key-result-type/key-result-type.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class KeyResultTypeComponent implements AfterContentInit {
142142
}
143143

144144
setFormControlValueToZero(formGroupMetric: any, form_control: string) {
145-
if (!formGroupMetric.get(form_control).value) {
145+
if (formGroupMetric.get(form_control) && !formGroupMetric.get(form_control).value) {
146146
formGroupMetric.get(form_control)
147147
.setValue(0, { emitEvent: false });
148148
}

0 commit comments

Comments
 (0)