byoungdale
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?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 3- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
byoungdale
I think the issue is that when a
Elementis passed to render_change, it does not allow for a customer event to be passed:for reference see source code here
So, when I change my test to this:
My input’s
phx-changeeventvalidate_urldoesn’t get triggered. Just a generic:changeevent which means my view doesn’t get theurlinput added to it.I think adding another match like this would work:
mcrumm
Try including the
_target:when you invoke render_change:Here’s an example from the LiveView tests:
https://github.com/phoenixframework/phoenix_live_view/blob/05bcd95fd40afc10a6b39f1c7ce9986495b21d5d/test/phoenix_live_view/integrations/elements_test.exs#L396-L399
We might be able to pick up the
phx-changeattribute from the input element automatically (avoiding the need to set _target manually) if someone wanted to PR thatbyoungdale
Thank you. The solution was actually not adding the target. The issue was passing in a map instead of a
key: mapwhich is what my liveview event handler was expecting.Here is what ended up working:
So, I had two problems. First, I was manually passing in the render_change event name when I did not need to, which caused the
render_eventpattern matching to fail inlive_view_test.ex, and then without manually passing in the event name, I was not passing the value correctly for myhandle_eventfunction.I only caught that because of the example you posted. Thank you for your help!