I’m having trouble figuring out how to test LiveViews that contain JS commands. Is this even possible? My mental model is a bit lacking here in terms of how browserless LiveView tests work. There doesn’t seem to be any mention of testing JS commands in the docs though would be happy to add them if I can figure this out.
My scenario:
def some_button(assigns) do
~H"""
<a href="#"
data-test-id="button"
phx-click={Phoenix.LiveView.JS.add_class("some-class", to: "body")}>click me</a>
"""
end
…the test:
test "click it", %{conn: conn} do
{:ok, view, _html} = live(conn, "/")
assert view
|> element("[data-test-id=button]")
|> render_click() =~ "resulting html" # Right side of the assertion isn't important since it never makes it here
end
I get the following error: (ArgumentError) no push command found within JS commands
Any insight would be much appreciated!