Reputation: 2205
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?
Upvotes: -1
Views: 204
Reputation: 677
The .point
property in Angular testing refers to the DebugElement
that wraps the component insteace.
The debugElement
provides access to the component, directives and elements inside the component's template.
So the fixture.point
return the DebugElement
, while fixture.componentInstance
return the actual component instace.
Some key differences:
fixture.point
allows you to query elements in the template using things like .query()
and .queryAll()
You can not do this with fixture.componentInstance
.fixture.componentInstance
allows you to access methods, properties and other things on the component class directly.When to use .point
:
When to use .componentInstance
directly:
So in summary:
.point
when you need to access the template or directives.componentInstace
When testing the component class members directly.I hope this will help you. If you need more clarification then please let me know. Cheers 🥂
Upvotes: 0