I have a LiveView that on mount parases a param from the URL.
def mount(%{"jwt" => jwt}, _session, socket) when is_binary(jwt) do
...
end
I wanted to test it with this code
defmodule MyAppWeb.SampleLiveTest do
use MyAppWeb.ConnCase
import Phoenix.LiveViewTest
test "success: mount", %{conn: conn} do
{:ok, view, html} = live(conn, "sample/?jwt=some_payload")
...
end
end
However, mount function does not match because on first unconnected mount I normally get “jwt” param. But on the second connected mount I get :not_mounted_at_router
.
Everything works fine when running the service because it is mounted at router. Both first unconnected and the second connected mount get the params correctly. But using the live(conn, path)
helper does not pass params to the connected mount.
What is the correct way to pass parameters in the test?