Phoenix_live_view: Mounting Page with 2 Live Views in Test Will Mount Wrong HTML with Correct View

Created on 25 Jun 2019  Â·  2Comments  Â·  Source: phoenixframework/phoenix_live_view

Environment

  • Elixir version (elixir -v): 1.9.0
  • Phoenix version (mix deps): 1.4.8
  • NodeJS version (node -v): v12.4.0
  • NPM version (npm -v): 6.9.0
  • Operating system: Mac OS 10.14.5

Actual behavior

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()

Expected behavior

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="
bug

Most helpful comment

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings