How to write test spec for following code

ngOnInit(): void {
let a=false;
if (a){
this.getName();
}
else{
alert(“name already fetched”);
}

}
getName(){
return “pp”;
}

//spec
it(‘should call getName if a is empty’, () => {
let a=true;
component.getName();

component.ngOnInit();
//expect(a).toBeTruthy();
expect(true).toBeTruthy();
expect( component.getName).toHaveBeenCalled();

});

but telling error…if path not taken in code coverage

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.