Reputation: 21134
When testing the DOM representation of a @Component
, you're able to query its nested elements via its fixture
fixture.debugElement.queryAll(By.css('.example'));
You can also filter by @Directive
fixture.debugElement.queryAll(By.directive(RouterLinkDirectiveStub));
Now, let's say you have an inner @Component
NzButtonComponent
used like this
<button nz-button>Example</button>
How can I precisely query for it? There is no By.component(...)
.
Upvotes: 2
Views: 5571
Reputation: 3357
You can select by CSS attribute if you use the nativeElement
instead of the debugElement
:
fixture.debugElement.nativeElement.querySelector<HTMLButtonElement>('[nz-button]');
For multiple elements the querySelectorAll
method can be used.
Upvotes: 2
Reputation: 657
Possibly you can use
fixture.debugElement.query(By.directive(AnyComponent))
it returns DebugElement
of that component
That works because in Angular Component inherits after Directive
Upvotes: 5