Unable to run angular unit test due to method present inside component constructor.
export class AppComponent {
name = 'Angular 4';
constructor(){
this.testMethod();
}
testMethod(){
console.log("test method");
}
testMethodNonc(){
console.log("test method nc");
}
}
//my spec file
describe('MyComponent', () => {
let fixture, element;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
]
});
fixture = TestBed.createComponent(AppComponent);
element = fixture.debugElement;
})
it('works', () => {
fixture.detectChanges();
expect(component.testMethodNonc()).toHaveBeenCalled();
});
});
when i tried to run unit test for testMethodNonc() ,function testMethod() also running along with this method since its present inside constructor. is it possible to execute testMethodNonc() alone by mocking function testMethod?