I am trying to mount a liveview in a test based on documentation examples:
test "GET /", %{conn: _conn} do
conn = get(conn, "/")
{:ok, view, html} = live(conn)
end
The liveview is defined at the root of my website, with β/β path set in the router:
scope "/", HelloWeb do
pipe_through :browser
live "/", Main.MainLive, session: [:user_id, :action, :current_user]
end
But running the test produces the error below (full stack at the end of the post):
(FunctionClauseError) no function clause matching in String.split/3
However, if I change the path of the Liveview from β/β to anything else, eg. β/testβ in both test and router, this error does not occur.
This looks to me like a bug in the testing framework but I am not sure since I am new to phoenix and elixir.
Does anybody know or have any hints on how to test a Liveview defined at the β/β path?
Thanks.
Error stack:
** (FunctionClauseError) no function clause matching in String.split/3
(elixir) lib/string.ex:407: String.split(nil, "/", [])
(phoenix) lib/phoenix/router.ex:887: Phoenix.Router.route_info/4
(phoenix_live_view) lib/phoenix_live_view/utils.ex:127: Phoenix.LiveView.Utils.live_link_info!/3
(phoenix_live_view) lib/phoenix_live_view/channel.ex:168: Phoenix.LiveView.Channel.maybe_call_mount_handle_params/2
(phoenix_live_view) lib/phoenix_live_view/channel.ex:523: Phoenix.LiveView.Channel.verified_mount/4
(phoenix_live_view) lib/phoenix_live_view/channel.ex:32: Phoenix.LiveView.Channel.handle_info/2
(stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:711: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:mount, Phoenix.LiveView.Channel}
1) test GET / (HelloWeb.Main.NavbarLiveTest)
test/hello_web/live/main/navbar_live_test.exs:7
** (FunctionClauseError) no function clause matching in String.split/3
The following arguments were given to String.split/3:
# 1
nil
# 2
"/"
# 3
[]
Attempted function clauses (showing 4 out of 4):
def split(string, -%Regex{} = pattern-, options) when -is_binary(string)-
def split(string, -""-, options) when -is_binary(string)-
def split(string, pattern, []) when -is_tuple(pattern)- or -is_binary(string)-
def split(string, pattern, options) when -is_binary(string)-
stacktrace:
(elixir) lib/string.ex:407: String.split/3
(phoenix) lib/phoenix/router.ex:887: Phoenix.Router.route_info/4
(phoenix_live_view) lib/phoenix_live_view/utils.ex:127: Phoenix.LiveView.Utils.live_link_info!/3
(phoenix_live_view) lib/phoenix_live_view/channel.ex:168: Phoenix.LiveView.Channel.maybe_call_mount_handle_params/2
(phoenix_live_view) lib/phoenix_live_view/channel.ex:523: Phoenix.LiveView.Channel.verified_mount/4
(phoenix_live_view) lib/phoenix_live_view/channel.ex:32: Phoenix.LiveView.Channel.handle_info/2
(stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:711: :gen_server.handle_msg/6
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3