Bergé Greg
1 min readMar 22, 2018

--

Yes, I think adding a «aria» instead of a «data-test» is much more valuable for the user.

I will give you a bit more context. I was working at Doctolib (french Zopdoc) with Olivier Tassinari (Material UI core maintainer). They have like 500 automated tests running on each PR and 500 other unit tests. So we faced this issue and Olivier proposed this solution, the «data-test». In fact it works very well, and even without Babel plugin it is not a big deal to have a «data-test» in the final code.

Now I had a bad feeling about it, because tests should adapt, not the code. We should not design our code to write test. And the second point was: «If I can’t even select a component without adding a custom attribute what about a blind user ?»

Now I only use text or accessibility selectors to write my tests. Using classes presents the same problem, a user can’t see it.

At Smooth Code we are using Jest Puppeteer to write integration tests. We use text or accessibility selectors and it works pretty well so far!

--

--