skeleton icon indicating copy to clipboard operation
skeleton copied to clipboard

Don't add data-testid attributes to component roots

Open oatmealproblem opened this issue 8 months ago • 6 comments

Describe the feature in detail (code, mocks, or screenshots encouraged)

Skeleton includes data-testid attributes in the root of each component. It would be great if those were not included in the distributed library.

What type of pull request would this be?

Enhancement

Provide relevant links or additional information.

Why: I work on a team with a dedicated test engineer. He assumes that data-testids are stable, and won't be changed without warning. It would be confusing to explain that some data-testids are not under our control and should not be relied on, especially since there's nothing obviously marking these data-testids as belonging to skeleton.

Feel free to change this to a bug; wasn't sure if bug or feature request was more appropriate for this.

oatmealproblem avatar Apr 09 '25 23:04 oatmealproblem

Building on my reply here: https://github.com/skeletonlabs/skeleton/discussions/3499#discussioncomment-12785069

We'll consider this, but we definitely need to be able to test our own components before we ship them. It may be possible to strip them, but my counter-proposal is to supply prefixes for these instead. And if possible, allow folks to override them if they prefer. Perhaps with the component API change this will be more likely.

@Hugos68 I'd appreciate your thoughts on this as well.

endigo9740 avatar Apr 10 '25 01:04 endigo9740

With the proposed component API, you could easily set the testid in the test, instead baking it into the component itself.

Prior to that, a skeleton prefix would be appreciated

edit: rereading this comment, it could maybe sound demanding. I hope it didn't come across that way. I really appreciate your work 🙏

oatmealproblem avatar Apr 10 '25 01:04 oatmealproblem

Building on my reply here: https://github.com/skeletonlabs/skeleton/discussions/3499#discussioncomment-12785069

We'll consider this, but we definitely need to be able to test our own components before we ship them. It may be possible to strip them, but my counter-proposal is to supply prefixes for these instead. And if possible, allow folks to override them if they prefer. Perhaps with the component API change this will be more likely.

@Hugos68 I'd appreciate your thoughts on this as well.

With our new component API we don't need to put data-testid on the components because we can pass them as a prop in the test suite

Hugos68 avatar Apr 10 '25 05:04 Hugos68

Just saw @oatmealproblem's comment, well that

Hugos68 avatar Apr 10 '25 05:04 Hugos68

Just occured to me @endigo9740 if the collapse props proposal goes through, what is there left to test? ZagJS will handle testing logic. No more Xclasses or anything. So what do we want to test at that point?

Hugos68 avatar Apr 11 '25 09:04 Hugos68

I still think we should reserve the right to augment the templates and features within reason. Not a total conversion. But if we for example want to replace a hardcoded icon with a slot/snippet/reactNode then that seems reasonable to test.

endigo9740 avatar Apr 14 '25 17:04 endigo9740

Why can't you provide a property to override the data-testid that you are providing? This should be a default property on all the components that users interact with. For example, controlDataTestid

We have recently upgraded from v2, and used data-testid, but now can not set to our expected stable values.

adamdva avatar Jul 22 '25 16:07 adamdva

Why can't you provide a property to override the data-testid that you are providing? This should be a default property on all the components that users interact with. For example, controlDataTestid

We have recently upgraded from v2, and used data-testid, but now can not set to our expected stable values.

Honest answer: just an oversight. We didn't often had use cases that people wanted to use our components for their testing use cases as you can wrap containers with display contents.

In the new Component API proposal this is solved. But we haven't found much time lately to work on it.

Hugos68 avatar Jul 23 '25 13:07 Hugos68

Starting in the upcoming Skeleton v4 release you will be able to pass any arbitrary attribute to the component template, this includes data-test attributes. Which are no longer provided per each component element by default. Keep out eye out for this release soon (tm)

endigo9740 avatar Sep 23 '25 16:09 endigo9740

Thanks. Though we just went through the pain of migrating from v2 to v3, we may not migrate to v4, depending on how much changes.

adamdva avatar Sep 23 '25 19:09 adamdva

@adamdva I wouldn't compare the scope of v3 and v4.

The v3 update included:

  • A top-to-bottom rewrite of Skeleton
  • Introduction of Zag-based components; including multi-framework support
  • Updates to support Svelte 5
  • Updates to Support Tailwind 4

(there was no way this wasn't going to have some level of pain)

The v4 update:

  • Minor CSS import change (you can drop @source)
  • Updates to the component tree structure, as described here.
  • The introduction of ~3-4 brand new components

We're aiming to automate as much of the migration as well, but there may still be some manual adjustments required due to nuance in each project and how folks consume components.

I know these changes can be painful, but they're necessary so we can finally solidify our APIs and begin supporting 4 total frameworks (Svelte, React, Vue, and Solid.js). So I appreciate everyone's effort in this journey, but the bumpy part is almost over.

endigo9740 avatar Sep 23 '25 19:09 endigo9740