I have below code in my constructor
constructor(
private ngxSpinner: NgxSpinnerService,
private userSecurityService: UserSecurityService,
private userInformationService: UserInformationService,
private navigateService: NavigateService,
private titleService: Title,
private router: Router
) {
this.router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
this.currentPath = event.url;
if(this.currentPath.indexOf('/custom-fields?view=edit') > -1) {
this.isCustomfieldsPage = true;
} else {
this.isCustomfieldsPage = false;
}
});
}
And below are my test cases
it('check if isCustomfieldsPage is true', () => {
spectator.component.isCustomfieldsPage = true;
spectator.component.currentPath = 'https://csc.com/admin/custom-fields?view=edit';
expect(spectator.component.isCustomfieldsPage).toBe(true);
});
it('check if isCustomfieldsPage is false', () => {
spectator.component.isCustomfieldsPage = false;
spectator.component.currentPath = 'https://csc.com/admin/manage-fields';
expect(spectator.component.isCustomfieldsPage).toBe(false);
});
The above test cases are not covering the code which is inside the constructor? How can I modify my code to work as expected. Please suggest. Thanks.