Closed ADolhov closed 4 years ago
Can you please provide a sample application or a failing test to our suite that reproduces the error? It would make our lives much much easier, thank you!
okie, will try to
I have one. Been hanging my head on this one for too long so thank you for the issue! ;)
https://github.com/snewcomer/live-comment/blob/master/test/live_comment_web/live/comment_test.exs
thanks guys, you are the best!
i realized, that Phoenix.LiveView live_render
within parent view template simply doesnt render nested view in tests (using Phoenix.LiveViewTest isolated_live
), only creates the container for nested view template
This was a small reproduction I started on as well with DOM.patch_id
Fixed on master. @snewcomer @ADolhov please give it a try and report back. Thanks!
I had same problem in tests, but now it works with master branch. Thanks!
I've been wrestling with issue for some time now and cannot come up with a working version. I'm using the latest version of LiveView as of today - 0.14.5
.
This is the relevant code in ".html.leex":
<%= content_tag(:ul, id: "messages", phx_update: "append") do %>
<%= for msg <- @messages do %>
<li id="<%= msg.id %>">
<strong><%= msg.user %></strong>:
<%= msg.text %>
</li>
<% end %>
<% end %>
It works as expected in Dev, yet fails in tests with:
setting phx-update to "append" requires setting an ID on each child. No ID was found on:
(phoenix_live_view 0.14.5) lib/phoenix_live_view/test/dom.ex:336: anonymous fn/3 in Phoenix.LiveViewTest.DOM.apply_phx_update_children_id/2
The test code is:
test "default mount, sending and receiving a message", %{conn: conn} do
{:ok, view, html} = live(conn, "/chat")
assert html =~ "No messages yet"
message = %Message{text: "Alf loves cats", user: "John", id: :os.system_time()}
send(view.pid, {:message, message})
assert render(view) =~ "Alf loves cats"
end
Do you think I'm missing something in the test setup?
Environment
Elixir 1.9.1 (compiled with Erlang/OTP 22)
Phoenix version (mix deps): phoenix 1.4.11 (Hex package) (mix)
Phoenix LiveView version (mix deps): phoenix_live_view 0.4.1 (Hex package) (mix)
NodeJS version (node -v): v12.6.0
NPM version (npm -v): 6.9.0
Operating system: ubuntu 18.04.3 LTS
Actual behavior
nested liveview with
phx-update="append"
property in container and rendered vialive_render
from parent liveview template works as expected on dev, but fails in parent liveview test withphx-update append/prepend containers require an ID
error onrender_click
action, despite container has an ID (withoutphx-update="append"
property test passes)Expected behavior
tests should pass