I’m curious as to what are the latest best practices when testing LiveView
components? My app was on an old version straight from Github, before the official 0.x
release. I started off by testing my components using mount/3
but that looks to have been deprecated. Having to run through the router might mean authenticating a user, which seems to distract from a more focused “unit” test.
I see now that we’re encouraged to make an actual call through the router to test the disconnected state:
use Phoenix.ConnTest
import Phoenix.LiveViewTest
@endpoint MyEndpoint
test "disconnected and connected mount", %{conn: conn} do
conn = get(conn, "/my-path")
assert html_response(conn, 200) =~ "<h1>My Disconnected View</h1>"
{:ok, view, html} = live(conn)
end
My first question is, what was the motivation for switching from a more direct method of testing (getting the view
and html
via mount_disconnected/3
) to running it through the router?
My next question is: is there still a way to test the disconnected state w/o going through the router?
Thanks for your advice!