phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.14k stars 921 forks source link

Nested LiveView form sends event to wrong LiveView in tests #3272

Closed krishandley closed 4 months ago

krishandley commented 4 months ago

Environment

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

SteffenDE commented 4 months ago

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