React testing library id instead of data-testid?
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: