I am trying to add a stable data-testid to a react-select component (specifically AsyncSelect) so that I can reliably select it in my Playwright E2E tests.
When I try to pass the data-testid prop directly to the <AsyncSelect> component, the prop is not rendered on the component's root <div> in the DOM.
My current workaround is to wrap the entire component in a new and apply the data-testid to that wrapper.
<div data-testid="my-selector-wrapper">
<AsyncSelect>....</>
</div>
This works, but it adds an extra, seemingly unnecessary DOM element just for testing.
My question is:
- Is wrapping react-select in a div the standard, accepted pattern for adding a test ID?
- Is there a built-in react-select prop or a different, cleaner method
(perhaps using the components prop or
classNamePrefix) that allows me to apply adata-testidto the component's root element without this wrapper?

getByRole. That said, I'm assuming you're stuck with test ids--in that case, if the library throws out props you add to it and the docs don't provide an alternative, then you're out of luck, and yes, you likely need to add an element just for testing.