Hi all,
I’m trying to test some Presence events in a LiveView. I want to test that the page changes when users enter and exit a LiveView. I’ve found success testing enter events by creating another test connection and joining the LiveView ({:ok, other_view, _} = live(other_conn, "/room/#{room.id}")
, but I’m not sure how to leave the live.
First I tried calling live_redirect
to go to a different LiveView (live_redirect(other_view, to: "/lobby")
, but this tried to redirect to "/room/lobby"
instead…
I looked at the source code for LiveViewTest.live_redirect
and tried
{_ref, _topic, pid} = other_view.proxy
Phoenix.LiveViewTest.ClientProxy.stop(pid, {:shutdown, :test})
but this doesn’t seem to change the other view on re-render. I also tried Process.exit(pid, :kill)
and this just exited the test. Is there some way to create the desired behavior? Should I be testing this in some other way? Thanks!
Edit: Ok I managed to get this to work for my use case with
other_room = room_fixture()
live_redirect(other_view, to: "/#{other_room.id}")
but I still feel like there should be a better solution. I also tried passing replace: true
to live_redirect
and it didn’t solve the problem trying to get to the lobby. Would still appreciate any input here