Stewart

Stewart

Liveview testing, testing multiple actions

Is there a way of manually triggering events from a liveview test?

I basically want to test a user doing a sequence of actions, eg Pressing a button, to open a form, then inputting a value in that form.

I can test a button press with render_click() on the element, but then it returns html and not a view.

How can i do the click and get back a view?

Marked As Solved

APB9785

APB9785

Creator of ECSx

In testing, the view is stateful/mutable, so you can do something like this:

{:ok, view, _html} = live(conn, "/path")

view |> element("#open-form-button") |> render_click

view |> form("#my-form", %{foo: %{bar: "baz"}}) |> render_submit

assert render(view) =~ "form was submitted!"

Also Liked

Stewart

Stewart

wow I had no idea it was stateful, that is incredibly useful!

Many thanks!

MMAcode

MMAcode

And here is brief explanation why is that view mutable: Is the test LiveView immutable or not?

brunoripa

brunoripa

Jeez, exactly the same misunderstanding for me :sweat_smile: Thanks !

Last Post!

MMAcode

MMAcode

And here is brief explanation why is that view mutable: Is the test LiveView immutable or not?

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
baxterw3b
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
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44608 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New