I have written few functions inside app components. Facing issue in increase the coverage summary on component method.
The test cases are working fine, it just that the few lines are not getting tracked in coverage summary.
app.component.ts
public initializeA(): void {
this.flagClone.client = {
build: null, //string
name: null, //string
id: null //string
}
}
public initializeB(): FlagResult {
this.isSearch = false;
return {
id: null, //string
description: null, //string
url: null, //string
client:{
build: null, //string
name: null, //string
id: null //string
}
};
}
app.component.spec.ts respective test cases
const testFlagResult: FlagResult = {
id: null, //string
description: null, //string
url: null, //string
client:{
build: null, //string
name: null, //string
id: null //string
}
};
it('should initializeA',() => {
const mock = spyOn(component,'initializeA').and.returnValue();
component.initializeA();
fixture.detectChanges();
expect(mock).toHaveBeenCalled();
});
it('should initializeB',() => {
const mock = spyOn(component,'initializeB').and.returnValue(testFlagResult);
component.initializeB();
fixture.detectChanges();
expect(component.isSearch).toBeTruthy();
expect(mock).toHaveBeenCalled();
});
expecting the below block to be included in coverage summary:
public initializeA(): void {
this.flagClone.client = {
public initializeB(): FlagResult {
this.isSearch = false;
Need some inputs that where I am missing it out.