Skip to content

Commit e7e980b

Browse files
committed
test: check if formcontrol is defined before using its value #1571
1 parent bbce9dc commit e7e980b

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
@@ -230,9 +230,9 @@ describe('KeyResultTypeComponent', () => {
230230
KeyResultMetricField.STRETCH_GOAL]])('Should call calculateValueForField with the correct enum', (values: MetricValue, changed: KeyResultMetricField, result: KeyResultMetricField) => {
231231
const spyInstance = jest.spyOn(component, 'calculateValueForField');
232232

233-
component.calculateValueAfterChanged(values, changed);
233+
component.calculateValueAfterChanged(values, changed, component.keyResultForm);
234234
expect(spyInstance)
235-
.toHaveBeenCalledWith(values, result);
235+
.toHaveBeenCalledWith(values, result, component.keyResultForm);
236236
});
237237

238238
it.each([
@@ -324,7 +324,7 @@ describe('KeyResultTypeComponent', () => {
324324
KeyResultMetricField.STRETCH_GOAL,
325325
{ stretchGoal: 5 }]
326326
])('calculateValueForField should calculate correct', (values: MetricValue, targetField: KeyResultMetricField, result: any) => {
327-
expect(component.calculateValueForField(values, targetField))
327+
expect(component.calculateValueForField(values, targetField, component.keyResultForm))
328328
.toEqual(result);
329329
});
330330

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
@@ -139,7 +139,7 @@ export class KeyResultTypeComponent implements AfterContentInit {
139139
}
140140

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

0 commit comments

Comments
 (0)