I have seen this code in the docs:
const fixture = MockRender(TargetComponent);
expect(fixture.point.componentInstance).toBeDefined();
But I noticed, we can do fixture.componentInstance also, so without the point. I searched the docs but I didn't find an answer. What exactly does ".point" do? When to use it, when to not use it?
The
.pointproperty in Angular testing refers to theDebugElementthat wraps the component insteace.The
debugElementprovides access to the component, directives and elements inside the component's template.So the
fixture.pointreturn theDebugElement, whilefixture.componentInstancereturn the actual component instace.Some key differences:
fixture.pointallows you to query elements in the template using things like.query()and.queryAll()You can not do this withfixture.componentInstance.fixture.componentInstanceallows you to access methods, properties and other things on the component class directly.When to use
.point:When to use
.componentInstancedirectly:So in summary:
.pointwhen you need to access the template or directives.componentInstaceWhen testing the component class members directly.I hope this will help you. If you need more clarification then please let me know. Cheers