4 ms·
Anyone using Django with HTMX? How are you writing UI tests for HTMX behaviour? The standard Django tests don't run JavaScript so what do you use for this and h
by seanwilson 3y ago
Anyone using Django with HTMX? How are you writing UI tests for HTMX behaviour? The standard Django tests don't run JavaScript so what do you use for this and how is the performance?
- fancy_pantser 3y agoAre you looking for something like Playwright or Cypress for end-to-end testing?
- seanwilson 3y agoAs close to end-to-end as practical. Playwright seems a lot heavier than standard Django tests.
- dqv 3y agoI think I might give it a try in one of my Django projects. In Elixirland we can use Wallaby to test LiveView. This example that uses Playwright with Django has very similar ergonomics: https://github.com/mxschmitt/python-django-playwright/blob/master/test_login.py https://github.com/mxschmitt/python-django-playwright/blob/m...
- hellcow 3y agoThat's the fun part. It's just HTML attributes, so you can test them without a full browser and JS engine. Just parse the HTML. Tests are super fast and never flaky.
- seanwilson 3y agoBut how are you checking that e.g. on submit the HTMX replaced the correct selector inside another form and that on submitting that form HTMX uses a HX-Redirect header to send you to the right page? If you're not testing that, don't you get cases of tests passing when the UI is actually broken in the browser?
- shicholas 3y agoWe can use playwright for these type of tests and still stay almost entirely in Python.
- yawaramin 3y agoJust submit a request, capture the response, and test it for whatever you like. Django has a test HTTP client that lets you craft whatever request you like, submit it, and captures the response. Once you have the response it's trivial to check its HTML content and its headers.