'How to filter with multiple conditions based on elements text in Cypress?

Given this HTML, I want to yield the .row element based on code = 002 and ref = 001

<div class="row">
    <span class="code">001</span>
    <span class="ref">002</span>
    <label>Some Label</label>   
</div>
<div class="row">
    <span class="code">002</span>
    <span class="ref">002</span>
    <label>Another label</label>    
</div>
<div class="row">
    <span class="code">002</span>
    <span class="ref">001</span>
    <label>Something</label>    
</div>

I would have thought the following should work but it doesnt filter anything

cy.get('.row').filter(`span.code:contains("002")span.ref:contains("001")`)

Even with one condition it seems to not work. Any idea what Im doing wrong?

Thanks for the help



Solution 1:[1]

As someone suggested in the comment I used a function that retrieve elements with jQuery. This is working

cy.get('.row').filter((i, $el) => {
        return Cypress.$($el).find('span.code:contains("002")').length > 0
          && Cypress.$($el).find('span.ref:contains("001")').length > 0;
      })

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kind-mug