I am using react testing library to test a dropdown component to check if a particular option is available on search and it used to work as expected using the following query that asserts that the option is selected or not.
expect(
screen.getByRole('option', {
name: 'ZAT',
selected: false,
})
).toBeInTheDocument();
Introduced a new feature where I highlight the search term in the options list and the tests started breaking as introducing the mark
or span
( with styling applied ) tag is creating an empty space in the test renderer because of which the query is no longer able to find the option with the exact text due to the spaces generated in the accessible element name ( even though the white spaces are collapsed in the DOM )
Wondering if anyone has any pointers as to how I can fix this so that the tests work as expected.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…