Currently, I am in the process of writing jasmine test cases for a specific block of code. While I have successfully covered the functions within the component, the if statements present within these functions remain untouched. Here are the if statements from one of the functions that require attention:
ngOnChanges(changes: SimpleChanges) {
this.branchuserRole = this.userService.getUser().getId();
if (this.data) {
if (this.branchuserRole === this.TEST) {
this.data = this.data.filter(task => task.assignedUser !== null);
this.data = this.data.filter(task => task.assignedRole === this.TEST);
this.summaryListLength = this.data.length;
} else {
this.summaryListLength = this.data.length;
}
Unfortunately, the entire if-else block is not covered in the current code coverage. Below is the snippet of code that I attempted to use for testing:
it('should call ngOnChanges function', () => {
const changes: any = '';
spyOn(component, 'ngOnChanges').and.callThrough();
component.ngOnChanges(changes);
expect(component.ngOnChanges).toHaveBeenCalled();
});
it('should set the value of data', () => {
const changes: any = '';
component.ngOnChanges(changes);
component.branchuserRole = TEST;
expect(component.data).toBeTruthy();
expect(component.data).toEqual(component.data.filter(task => task.assignedUser !== null));
expect(component.taskData).toEqual(component.taskData.filter(
task => task.assignedRole === TEST));
expect(component.summaryListLength).toEqual(component.data.length);
});