angelikatyborska

angelikatyborska

Intro

Currently when mounting a LiveView with Phoenix.LiveViewTest.live/2 you can get the full page HTML as a string, but then, after doing some updates (triggering events etc.), it’s no longer possible to get the up-to-date full page HTML. It’s only possible to get the HTML of the LiveView with Phoenix.LiveViewTest.render/1, without any layouts.

What am I asking for?

It would be great if there was a function like render_page(live) or page_html(live) in Phoenix.LiveViewTest that would allow you to get the up-to-date full page HTML at any time of the LiveView’s lifecycle.

Is my suggestion easily implemented?

This is a post that triggered my request: In a LiveView test, how can I get the full page HTML after the initial render?

As mentioned in that post, there is technically an unofficial way to get the full page HTML by using the private genserver Phoenix.LiveViewTest.ClientProxy which is able to produce a full page HTML after LiveView updates because it’s needed for Phoenix.LiveViewTest.open_browser/2. I believe that makes it reasonably easy to implement what I’m asking for.

Would my suggestion benefit Phoenix of the community as a whole?

It would make it possible to, in tests, send the HTML of the LiveView in the current state to an HTML validator which helps to catch some types bugs (duplicate ids, invalid tag nesting, labels not assigned to any inputs etc.). HTML validators work on full documents, not fragments, hence the need for the full page HTML.

I won’t lie, I think the number of people who would actually do this is very low. My request might be a bit selfish - I have written a library that makes it easy to validate HTML in tests that I’ve been using for years, and this change would make my library more useful for LiveView tests. But I would like to encourage more people to do HTML validation because it helps produce higher quality web apps and catch some accessibility issues.

There might be completely different use cases for this that are not crossing my mind currently.

Any downsides to adding this? Definitely having one more public function to maintain is a downside.

Please also consider volunteering to work on any implementations yourself

I would love to work on this. I would just need approval on the chosen function name, I don’t feel very confident about my proposed names.

Showing Posts 1 to 2

sodapopcan

sodapopcan

I think this is a great idea and I would be interested in using something like this. Since this is essentially linting, it would be ideal if it could be a heex extension (being that it is already html-aware) and not have to use tests. I’m not sure that heex is extensible, though.

Is your current library available anywhere?

Also, does the Phoenix.LiveViewTest.ClientProxy output produce the exact same output as open_browser? I ask because I’ve notice that there are some discrepancies in how open_browser renders root.html.heex content vs what is actually rendered in the running app.

EDIT: I think any of render_page, render_html, or even render_dom are all fine options.

angelikatyborska

angelikatyborska OP

Yes, my library is this: vnu-elixir

The only discrepancy I noticed between the real running app and the HTML returned by Phoenix.LiveViewTest.ClientProxy is that the latter is missing a DOCTYPE because Floki removes that. Maybe there are more discrepancies but I haven’t been testing LiveViews long enough to notice.

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews