here is my code example
<div class="dropdown" data-testid="dropdown">
<div class="option" data-testid="option">
<b>[AF]</b> Afghanistan
</div>
<div class="option" data-testid="option">
<b>[AL]</b> Albania
</div>
<div class="option" data-testid="option">
<b>[DZ]</b> Algeria
</div>
</div>
What I need to do is to access the first element by its text to trigger the userEvent.selectOptions
const dropdown = getByTestId('dropdown');
userEvent.selectOptions(dropdown, screen.getByText('[AF] Afghanistan'))
What I get is :
TestingLibraryElementError: Unable to find an element with the text: [AF] Afghanistan. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
It's obviously because the text I'm trying to query is broken by elements.
Please note, that this is not a select/option dropdown and it doesn't have any accessible roles so I can only query it by screen.getByText