-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Recommended Type-Safe Way to Add locators like "data-testid" to MUI / MUI X Components? #22126
Copy link
Copy link
Open
Labels
scope: all componentsWidespread work has an impact on almost all components.Widespread work has an impact on almost all components.support: pro standardSupport request from a Pro standard plan user. https://mui.com/legal/technical-support-sla.Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla.testtype: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.
Metadata
Metadata
Assignees
Labels
scope: all componentsWidespread work has an impact on almost all components.Widespread work has an impact on almost all components.support: pro standardSupport request from a Pro standard plan user. https://mui.com/legal/technical-support-sla.Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla.testtype: enhancementIt’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.
The problem in depth
We’re using MUI + MUI X with React + TypeScript, and our QA team uses Playwright + TS for automation.
We need a reliable, type-safe way to add locators like
data-testidto MUI components (fields, buttons, dropdowns, autocomplete, Data Grid, charts, etc.).Right now, we’ve been using custom types like these:
This works in some cases, but it’s basically bypassing TypeScript, and we’ve hit edge cases where we had to inspect MUI’s actual internal prop types.
We want to refactor this and use the proper MUI/MUI X way to pass
data-testidto the real rendered HTML elements without working around TS.A few questions:
What’s the recommended way to add
data-testidto MUI / MUI X components in a type-safe way?Is there any built-in MUI support for automation locators across components?
Are people extending MUI module types for this, or handling it per component?
How are other teams solving this?
Would appreciate any advice from teams doing this at scale.
Your environment
`npx @mui/envinfo`
Search keywords: locators, data-testid, testid
Order ID: 127117