Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

React testing library id instead of data-testid?

Writer Sophia Terry

Would be any difference if I used HTML id attribute instead of data attributes like data-testid?

Reference for the use of data-testid in testing:

1 Answer

On the surface, I don't see any technical difference.

But in terms of readability, data-testid may notice other developers that this is used for test case specifically, while id is may be in terms of styling.

Also id or class selectors can be changed more often if implementation changes.

Reference:

Making your UI tests resilient to change

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy