Proposal: prefer targeting interactive elements, document dataTest exports #224
Replies: 2 comments 13 replies
-
Breaking dataTest changes I'd like to propose that we do not consider removal of a Thoughts welcome, please discuss in this thread => |
Beta Was this translation helpful? Give feedback.
-
we might want to ALWAYS have a root |
Beta Was this translation helpful? Give feedback.
-
This is a synthesis of the discussions in #218 and #219 and LIBS-118 (for transfer)
We should formalize a policy about which elements within a component get
data-test
attributes and how we communicate this behavior to the consumer.I propose the following simple guidelines:
${dataTest}-search
or${dataTest}-output
not${dataTest}-input
and${dataTest}-div
.Button
is just a styledbutton
) or one clear "primary" element it is OK to omit the postfix from this element (i.e.<button dataTest={props.dataTest} />
). This should be used carefully, however, in cases where a future version of the library might increase the complexity of the component.dataTest
props. The one exception, only if deemed necessary, is${dataTest}-container
on the ROOT element of a container. This is allowed, as it could occasionally be helpful for targeting and should be stable.dataTest
properties to additional functional elements in a component as they are needed or requested by consumers. They should, however, be named and added in a way that assumes that at some point in the future ALL focusable and dynamic elements will have dataTest properties, so the chosen names should be suitably unique.dataTest
assignment or CHANGING THE TYPE OF TARGETED ELEMENT is technically a breaking change (for tests, not for runtime) so should be avoided unless absolutely necessary. We should decide whether to trigger major version bumps for dataTest changes or to only guarantee dataTest stability across patch versions, which I think could be acceptable (let's discuss this separately, thread below)dataTest
prop (i.e. anotherui
component) it should inherit from the parent's passeddataTest
prop - i.e. if the parent component renders aButton
, thatButton
should be rendered with dataTest${parentDataTest}-${buttonFunction}
, so that the specifieddataTest
propagates all the way down to the final plain DOM elementsdataTest
elements it "exports", similar to the documented table of proptypes. (cc @KaiVandivier)Beta Was this translation helpful? Give feedback.
All reactions