I am trying to write a test for a phx-change event I have on a input element inside a form. The phx-change happens only on the input element, not a change on the form.
<%= url_input f, :url, phx_debounce: "2000", phx_change: "validate_url" %>
Everything works functionally, but I wrote this test for the element:
test "successful URLs", %{conn: conn} do
{:ok, view, _html} = live(conn, "/submit")
assert view
|> element("#submit-item-form_url")
|> render_change(:validate_url, %{url: "https://elixir-lang.org/learning.html"}) =~
"value=\"Learning resources - The Elixir programming language\""
But, when I run the test, I get this error:
1) test successful URLs (CommunWeb.Live.SubmitItemLiveTest)
test/commun_web/live/submit_item_live_test.exs:15
** (FunctionClauseError) no function clause matching in Phoenix.LiveViewTest.render_event/4
The following arguments were given to Phoenix.LiveViewTest.render_event/4:
# 1
#Phoenix.LiveViewTest.Element<selector: "#submit-item-form_url", text_filter: nil, ...>
# 2
:change
# 3
:validate_url
# 4
%{url: "https://elixir-lang.org/learning.html"}
Attempted function clauses (showing 1 out of 1):
defp render_event(%Phoenix.LiveViewTest.View{} = view, type, event, value) when is_map(value) or is_list(value)
code: |> render_change(:validate_url, %{url: "https://elixir-lang.org/learning.html"}) =~
stacktrace:
(phoenix_live_view 0.17.10) lib/phoenix_live_view/test/live_view_test.ex:887: Phoenix.LiveViewTest.render_event/4
test/commun_web/live/submit_item_live_test.exs:20: (test)
It is complaining that the private function render_event
is expecting a %Phoenix.LiveViewTest.View{}
type, but the render_change
function expects an Phoenix.LiveViewTest.Element
type, which is what i am passing.
I think I am missing something or is this not the correct way to test a render_change event on an input element?