I am writing test case for the conditional if=else statement in angular , test case is not having any error, but when I run the ng test then in code coverage its showing if-else statement is not executed.
Please help me to understand how to write the state case for if-else
bellow is the test case code I wrote ::
it('Should initialize Edit or View screen based on redirect url', () => {
const title = 'Edit';
const titleView = 'View';
if (title === 'Edit') {
component.mode = 'Edit';
expect(component.isEditScreen).toBe(true);
expect(component.editModeDisabled).toBe(true);
component.damageForm.controls['address'].disable();
component.downclaim.disable();
component.getEditDefaultDropdownValues();
component.editDamageById(1);
} else if (titleView === 'View') {
expect(component.isViewScreen).toBe(true);
expect(component.viewModeDisabled).toBe(true);
component.damageForm.disable();
component.viewDamageById(1);
}
});
here is the component. ts file code for same test case
initEditOrView() {
this.damageCode = this.route.snapshot.params.id;
if (this.route.snapshot.data.title === 'Edit') {
this.mode = 'Edit';
this.isEditScreen = true;
this.editModeDisabled = true;
this.damageForm.controls['address'].disable();
this.downclaim.disable();
this.getEditDefaultDropdownValues();
this.editDamageById(this.damageCode);
} else if (this.route.snapshot.data.title === 'View') {
this.isViewScreen = true;
this.viewModeDisabled = true;
this.damageForm.disable();
this.viewDamageById(this.damageCode);
}
}