by bornelsewhere · 3y ago · 0 comments
Frontend frameworks all have a way to unit- and integration-test their components without resorting to Cypress or Playwright. How do you integration-test the effect of your hypermedia enhanced applications without a (headless) browser? Using Chrome for a few end-to-end tests is fine. But it is not a replacement for in process RackTest (to give a Rails specific example).
From a quick glance testing is not addressed in this book either.
assert response.json() == {"detail": "Item already exists"}
You can write: assert f"<b>Item already exists</b>" in response.render().decode()
One thing I found using HTMX (or just HTML) is that the apps are less fragile. I know that if I return a chunk of HTML, the browser will render it the same way every time. With a JSON-based SPA, maybe that chunk of JSON ends up triggering multiple side effects, re-renders, etc. which can behave differently depending on the current application state. This all affects the amount of testing that I feel comfortable with.[0]: https://fastapi.tiangolo.com/tutorial/testing/?h=testing#ext...
HTMX writes quite a bit of the logic for us. We don’t need to test that logic because we can assume that it’s been tested. We only need to test the remaining logic, of which there is less and it’s less messy because it’s more declarative (if I understand HTMX).
If we use an input of type “email” we also don’t test if its validation works.