Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveviewTest render_submit behaves differently if form is in parent liveview or child live_component #2579

Closed
danturn opened this issue Apr 5, 2023 · 2 comments

Comments

@danturn
Copy link

danturn commented Apr 5, 2023

Environment

  • Elixir version (elixir -v): 1.14.0
  • Phoenix version (mix deps): 1.7.2
  • Phoenix LiveView version (mix deps): 0.18.18
  • Operating system: MacOs Ventura 13.1
  • Browsers you attempted to reproduce this bug on (the more the merrier): n/a
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes

Actual behavior

if i have a form submit event handler that does a push_patch in a parent liveview, when submitting the form in a test like this:

  test "can assert on update from parent syncronously", %{conn: conn} do      
    {:ok, view, _html} = live(conn, ~p|/|)                                    
                                                                              
    view                                                                      
    |> element("#parent-form")                                                
    |> render_submit()                                                        
  end   

the handle_params function is called and completes before the test exits

however, if i have the same event handler in a child component and initiate the push_patch from the child, the same test (with the form in the component rather than the parent) exits before the handle_params function returns

  test "cannot assert on update from child syncronously", %{conn: conn} do    
    {:ok, view, _html} = live(conn, ~p|/|)                                    
                                                                              
    view                                                                      
    |> element("#child-form")                                                 
    |> render_submit()                                                        
  end     

in my case, i have db queries in handle_params and end up with db errors:

13:01:16.743 pid=<0.432.0> [error] Postgrex.Protocol (#PID<0.432.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.497.0> exited

after the test ends

Expected behavior

render_submit should behave the same in both instances?

@danturn
Copy link
Author

danturn commented Apr 5, 2023

I've pushed the repo if it helps

https://github.com/danturn/liveview-async-issue

@chrismccord
Copy link
Member

You can await the navigation with an assert_patch call. In the context of a LC, it sends a message to the parent to navigate, so you need to await this event being sent. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants