Testing flash message from LiveView

if you explicitly call render/1 after render_click/2, you can assert if the returned HTML includes the flash message (which is great, because we avoid testing implementation details):

{:ok, view, html} = live(conn, "/show/#{slug}")

assert html =~ "Active" #The button has this text (pass)
assert render_click(view, :unsubscribe) =~ "Activate this show" #Components that update after the click (pass)
# assert get_flash(conn, :info) == "Show disabled!" #Flash message (assertion failed)
# do this instead 👇
assert render(view) =~ "Show disabled!"

I found this solution here Send event from live component to parent Live View - #6 by MMore

1 Like