Hacker News new | ask | show | jobs
by capableweb 919 days ago
> IMHO UI tests are just too difficult to be worth bothering with in most situations.

Yes, that's because you're doing them wrong.

Don't mess around with the "golden master" testing (edit: seems the frontend ecosystem call that "Snapshot Testing" actually, but it's the same) you see bunch of projects do, that compare the old DOM vs the new DOM you accept/deny changes based on component render output. That's a waste of time and won't actually prevent bugs.

Instead, extract the logic-heavy parts out from your components, then put those under unit tests, like any other code you write.

Boom, easy to maintain, verifies your implementation and makes your UI easier and faster to refactor and build in the first place.

1 comments

But then those are by definition not UI tests.

In an ideal world one might argue that everything testing-worthy (ie. the logic-heavy parts) is already factored out from the UI components but getting to that point either needs a good amount of foresight and discipline or some a lot of refactoring which is difficult to trust without existing UI tests...