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?

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!"
1 Like

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

Many thanks!

1 Like