'How to invoke text of a div properly on cypress

I'm having troubles with the invoke('text') of this div and I don't know why:

<div class="MuiDataGrid-cell MuiDataGrid-cell--textLeft" role="cell" data-field="description" data-colindex="2" aria-colindex="3" tabindex="-1" style="min-width: 234px; max-width: 234px; min-height: 36px; max-height: 36px; line-height: 35px;">TEXT</div>

My code is this:

cy.get('[data-rowindex="0"]').find('[data-field="description"]').invoke('text').then(text => {
            cy.get('.css-1e8jzdq').eq(1).find('input').type(text)
        })

What I want it to take the text of the div and use it to type into a search input but it doesn't work because cy.type() cannot accept an empty string. You need to actually type something.

I don't know what I'm missing with this invoke... any help?



Sources

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

Source: Stack Overflow

Solution Source