Hacker News new | ask | show | jobs
by luontola 534 days ago
I've successfully used (for 3+ years in multiple projects) an approach similar to BeautifulSoup's get_text() function to assert the whole visible text of a component. You can implement it in other languages with a few regexes.

One addition makes it an order of magnitude more versatile: a way to visualize non-textual information as text in the tests. For example add a data-test-icon attribute which contains the replacement text that should be shown in tests. Another method is to parse the HTML and write custom visualization for some elements, so that you get useful default visualization for at least form elements and such, without having to repeat the data-test-icon attribute every time.

See https://martinfowler.com/articles/tdd-html-templates.html#Bo...

1 comments

I’ve done something similar, but using pandoc to convert the html to text, so tables and bullet points are rendered appropriately.