Phoenix.LiveViewTest.follow_redirect
follow_redirect
, go back to Phoenix.LiveViewTest module for more information.
Follows the redirect from a render_*
action or an {:error, redirect}
tuple.
Imagine you have a LiveView that redirects on a render_click
event. You can make it sure it immediately redirects after the
render_click
action by calling follow_redirect/3
:
live_view
|> render_click("redirect")
|> follow_redirect(conn)
Or in the case of an error tuple:
assert {:error, {:redirect, %{to: "/somewhere"}}} = result = live(conn, "my-path")
{:ok, view, html} = follow_redirect(result, conn)
follow_redirect/3
expects a connection as second argument.
This is the connection that will be used to perform the underlying
request.
If the LiveView redirects with a live redirect, this macro returns
{:ok, live_view, disconnected_html}
with the content of the new
LiveView, the same as the live/3
macro. If the LiveView redirects
with a regular redirect, this macro returns {:ok, conn}
with the
rendered redirected page. In any other case, this macro raises.
Finally, note that you can optionally assert on the path you are being redirected to by passing a third argument:
live_view
|> render_click("redirect")
|> follow_redirect(conn, "/redirected/page")