Lifecycle hook of AfterViewInit in Jasmine test
I often directly call the life cycle hooks from each spec whenever necessary. And this works.
Because this gives the flexibility to manipulate any data before calling ngAfterViewInit()
or ngOnInit()
.
I have also seen few angular libraries test spec using it in the same way. For eg, check this videogular spec file. So there is no harm in calling those methods manually.
Also copying the same code here, just to avoid the link to be broken in future.
it('Should hide controls after view init', () => {
spyOn(controls, 'hide').and.callFake(() => {});
controls.vgAutohide = true;
controls.ngAfterViewInit();
expect(controls.hide).toHaveBeenCalled();
});