I am learning unit testing in Angular using jasmine. I have a component in which the ngOnInit()
method has certain service calls. Below is my ngOnInit()
method:
ngOnInit() {
this.componentInteractionService.resetCurrentMenu();
this.router.paramMap.subscribe(params => {
this.currentContentUrl = params.get("currentContentUrl");
let tmp = params.get("contentTitle");
this.contentSubstitle = params.get("contentSubtitle");
if (tmp == undefined) {
let url = this.currentContentUrl;
this.contentTitle = url.substring(url.lastIndexOf("/") + 1, url.length);
}
else {
this.contentTitle = tmp;
}
});
}
So how should I test so that all the lines of the ngOnInit()
method are covered? I mean I need full code coverage.
In my spec.ts
:
it('should call all methods in ngOnInit', () => {
component.ngOnInit();
.......
.......
});
What should I write after component.ngOnInit();
? Please help. I can test the first line which is:
this.componentInteractionService.resetCurrentMenu();
But how to test the rest of the lines?