phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML

Home Page:https://hex.pm/packages/phoenix_live_view

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nested LiveView form sends event to wrong LiveView in tests

krishandley opened this issue · comments

Environment

  • Elixir version (elixir -v): Elixir 1.15.5 (compiled with Erlang/OTP 26)
  • Phoenix version (mix deps): 1.7.1
  • Phoenix LiveView version (mix deps): Latest from github
  • Operating system: MacOS

Descritpion

In tests with Phoenix.LiveViewTest, a nested LiveView form submit event goes to the parent LiveView but in real browsers the event is correctly sent to the nested LiveView.

An example repo can be found here https://github.com/krishandley/liveview_nested_form_test

Hi there, thank you for the report. The functions in Phoenix.LiveViewTest target a specific view. In order to send the submit event to the correct view, you'll need to explicitly target it using find_live_child/2 or live_children/1:

    assert child_view = find_live_child(view, "nested")

    child_view
    |> form("#nested_form", %{})
    |> render_submit()

So I'd say it works as expected. If you think the documentation could be clearer, feel free to submit a PR :)