I'm trying to test a dropdown component rendering certain options in the correct order.
Currently the test-code looks like:
const dropdown = getByTestId('my-dropdown');
const selectOptions = dropdown.ownerDocument.querySelectorAll(
'.Select-menu .Select-option button'
);
expect([...selectOptions].map(o => o.innerText)).toEqual([
'All options',
'Option X',
'Option Y',
'Option Z',
]);
This testing approach works, but it feels like it depends too much on the implementation details of my component. One of the core tenets of react-testing-library
is that we want our tests to avoid including implementation details of components.
Does anybody have any insights on how I can assert that my dropdown renders options in the correct order? How would you do this with react-testing-library
?