Skip to content

Commit c04a544

Browse files
committed
test: check if formcontrol is defined before using its value #1571
1 parent 08e0307 commit c04a544

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
@@ -137,7 +137,7 @@ export class KeyResultTypeComponent implements AfterContentInit {
137137
}
138138

139139
setFormControlValueToZero(formGroupMetric: any, form_control: string) {
140-
if (!formGroupMetric.get(form_control).value) {
140+
if (formGroupMetric.get(form_control) && !formGroupMetric.get(form_control).value) {
141141
formGroupMetric.get(form_control)
142142
.setValue(0, { emitEvent: false });
143143
}

0 commit comments

Comments
 (0)