mercredi 29 janvier 2020

Testing Library: How to get parent node that has a child with Text

In Testing Library, I'm trying to find a way to find elements whose children match a criteria:

<div class="classA">
    <div class="classB">
        <div class="classC">
            some text
        </div>
    </div>
    <div class="classB">
        <div class="classC">
            more text
        </div>
    </div>
</div>

And I would like to find

<div class="classB">
    <div class="classC">
        some text
    </div>
</div>

I tried: getByText(container, 'some text', {selector: 'classB'}) but it returns

<div class="classC">
    some text
</div>

What am i missing to find the container/component/parent that would contain this text

Aucun commentaire:

Enregistrer un commentaire