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

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
alice
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New

Other popular topics Top

New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
greenz1
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement