karang
Liveview testing render changes before submitting form
Hello I am trying to test my liveview and I want to test the editing of a resource through liveview. So I have something like this:
{:ok, view, _html} = live(conn, ~p"/my_resource/#{id}/edit")
params = %{some_key: "some value"}
{:ok, view, html} =
view
|> form("#my-form")
|> render_change(params)
|> render_submit()
|> follow_redirect(conn, ~p"/my_redirect_route")
My problem is that the return type of render_change is not what render submit is expecting and it errors out on the render_submit() line. This is the error I get:
** (FunctionClauseError) no function clause matching in Phoenix.LiveViewTest.render_event/4
The following arguments were given to Phoenix.LiveViewTest.render_event/4:
# 1
"<div>my html string</div>"
# 2
:submit
# 3
%{}
# 4
%{}
I have tried using the element/3 function and splitting this out into 2 steps but that failed also. Is there a way I can render some changes and then submit the form? I am sure there is I am just missing something… Thanks!
Marked As Solved
RudManusachi
LiveViews are
GenServer’s under the hood
render_change is modifying the state of the live_view process and returns rendered result as a string to assert on if needed.
Once we got view via
{:ok, view, _html} = live(conn, ~p"/my_resource/#{id}/edit")
we should be able to
# modify the view (this will also return the resulting html so we can assert on its content if needed)
html =
view
|> form("#my-form")
|> render_change(%{some_key: "some value"})
# now the state of the `view` is modified, so we can submit the form and try to follow redirect
view
|> form("#my-form")
|> render_submit()
|> follow_redirect(conn, ~p"/my_redirect_route")
1
Also Liked
karang
Last Post!
karang
Popular in Questions
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I would like to know what is the best IDE for elixir development?
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
Credo is smart enough to check for (something like) this:
assert length(the_list) == 0
with this response:
Checking if an enum is empt...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









