Reputation: 147
I try to test my template, if a certain text was rendered. The first result with "textICanFindWithByText" works great with ByText.
The text im looking for and where I have problems with is "textIWantToFindWithByTextOrByTextContent"
I cant seem to get it work with ByText - therefore I conclude that ByTextContent needs to be used, as the text I am looking for is nested within another div. Still getting null as returned value.
I personally cant find any references or syntax guides, so I can learn which selector I need to use.
Id be very happy, if someone could give me the correct answer with maybe an explanation to it.
Thanks in advance!
component.html
<div class="container-fluid mb-2 py-3 card-border-Resp card-container-bg-grey">
<div class="row">
textICanFindWithByText
<div class="col-12 col-md-9 mb-2 py-2 card-info-bg-grey-Resp">
textIWantToFindWithByTextOrByTextContent
</div>
</div>
</div>
component.spec.ts
const firstResult = spectator.query(byText('textICanFindWithByText'));
const secondResultFirstTry = spectator.query(byText('textIWantToFindWithByTextOrByTextContent'));
const secondResultSeconddTry = spectator.query(byTextContent('textIWantToFindWithByTextOrByTextContent',{selector: 'div'}));
Upvotes: 2
Views: 500