Background: There's 2 Live Views on one page. I want to select the second one to test. I was expecting if I set the assignment, it would select the correct View to mount.
Calling a mount after get request fails with wrong HTML.
{:ok, _view, html} =
conn
|> get(Routes.dashboard_path(conn, :details))
|> assign(:live_view_module, AppWeb.Details)
|> live()
HTML from other View is rendered in the html being returned, but the view seems to be correct:
%Phoenix.LiveViewTest.View{
child_statics: %{},
children: #MapSet<[]>,
connect_params: %{},
dom_id: "phx-zXSJOXDg",
endpoint: AppWeb.Endpoint,
module: AppWeb.Details,
mount_path: "/mydetails",
pid: #PID<0.435.0>,
proxy: #PID<0.434.0>,
ref: #Reference<0.2773653526.2447376385.14958>,
rendered: nil,
router: AppWeb.Router,
session_token: "SFMyNTY.g3QAAAACZAAEZGF0YWgCYQF0AAAABWQAAmlkbQAAAAxwaHgtelhTSk9YRGdkAApwYXJlbnRfcGlkZAADbmlsZAAGcm91dGVyZAAaRWxpeGlyLk91ckJpZ0RheVdlYi5Sb3V0ZXJkAAdzZXNzaW9udAAAAAJkAAZsb2NhbGVtAAAAAmVuZAAHdXNlcl9pZGIAABZrZAAEdmlld2QAIEVsaXhpci5PdXJCaWdEYXlXZWIuRmVlZGJhY2tGb3JtZAAGc2lnbmVkbgYA2DLMjmsB.aP5qrHjQKzs93HyQtxQAgfn12T0mmA-oA85wbJylxjU",
static_token: nil,
topic: "phx-bZmpkrw3ycU="
This is a known limitation for testing "widget style" live views. If multiple root LiveViews exist on a static controller rendered page, we only select the first one. Your option today would be to move your root view up to a LiveView and use the children/1 to obtain both children in the test. We'll explore extending the testing API for this use case, but other things need to be tackled first. Thanks!
Most helpful comment
For posterity, https://github.com/phoenixframework/phoenix_live_view/pull/284