Skip to content

Commit f9bc527

Browse files
committed
test: check if formcontrol is defined before using its value #1571
1 parent 6aa3417 commit f9bc527

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([
@@ -341,7 +341,7 @@ describe('KeyResultTypeComponent', () => {
341341
{ stretchGoal: 5,
342342
commitValue: -2 }]
343343
])('calculateValueForField should calculate correct', (values: MetricValue, targetField: KeyResultMetricField, result: any) => {
344-
expect(component.calculateValueForField(values, targetField))
344+
expect(component.calculateValueForField(values, targetField, component.keyResultForm))
345345
.toEqual(result);
346346
});
347347

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
@@ -144,7 +144,7 @@ export class KeyResultTypeComponent implements AfterContentInit {
144144
}
145145

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

0 commit comments

Comments
 (0)