Test a LiveView used with live_render in a template

I have a LiveView incorporated in a Phoenix template using the live_render function. I have seen in the doc this is not the recommended way to do it. But I am just trying to add some live magic to an existing (big) template, so I don’t want to transform all my template in a LiveView.

I am trying to find a way to test the resulting page. But in the documentation, I can only find instructions to a test a LiveView served directly by the Router. I have no specific path for that LiveView, I just have a path for the parent template.

I have tried this:

  test "connected mount", %{conn: conn} do
    # this is the parent template
    conn = get(conn, "/backoffice/datasets/new")
    assert html_response(conn, 200) =~ "xxx"
    # trying to mount the view in a connected state
    {:ok, _view, html} = live(conn)

But the live function returns {:error, :nosession}

Is there any way to test a liveView embedded in a regular template?

You can use live_isolated/3 to spawn the embedded LV to test.

1 Like

oh excellent, thanks, I will try!