How do I add typescript support for my custom data-testid attribute? #11345
Unanswered
colinblaise
asked this question in
Help/Questions
Replies: 1 comment 1 reply
-
I was able to get the typescript enforcement working with the following code in a type test = "hello" | "world";
declare module "@vue/runtime-dom" {
interface HTMLAttributes {
"data-testid"?: test;
}
}
export {}; This code was provided to me by claude.ai after a few rounds of discussion. The only problem I'm still trying to solve is I'm not receiving any autocomplete syntax in the template when I start specifying a value for data-testid. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using playwright for my E2E tests and I'm decorating my components with
data-testid
attributes to target them.Instead of hardcoding a value for data-testid in both my components and in the tests, I'd prefer to have a type that contains all of the valid data-testid values.
e.g.
Doing this forces me to keep the type up to date, and in my tests I'll be able to create a helper function to easily target my ids.
e.g.
I've tried extending my
vue.d.ts
file but nothing seems to be working. I also can't find any exiting docs on what interfaces to extend to accomplish this.Beta Was this translation helpful? Give feedback.
All reactions