View Source Heyya.LiveTest (heyya v0.2.0)

Heyya.LiveTest module provides helper methods that make it easier to write a more linear live view test. It takes care of the fact that there's connection state, view state, and last html state.

These ideas origionally came from: https://www.reddit.com/r/elixir/comments/ydyt2m/better_liveview_tests/

This implementation doesn't hide follow (in large part because of the ergonomics of follow_redirect being a macro)

example

Example

defmodule MyPhoenixWeb.ListLiveTest do
  use Heyya.LiveTest
  use MyPhoenixWeb.ConnCase

  test "widget list with new button", %{conn: conn} do
    start(conn, ~p|/widgets|)
    |> assert_html("Widgets List")
    |> click("a", "New Widgets")
    |> follow(~p|/widgets/new|)
  end
end

Link to this section Summary

Functions

This method clicks on an element that's selected via selector then renders the result. Finally returning a new LiveTestSession with updated rendered html

Sets the form specified by the selector to a new value.

Macro that creates code to start a new LiveTestSession. This takes in a plug connection (Usually from your ConnTest)

Submits the form and renders the result of submitting.

Link to this section Functions

Link to this function

assert_element(test_session, selector, text \\ nil)

View Source
@spec assert_element(Heyya.LiveTestSession.t(), String.t(), String.t() | nil) ::
  Heyya.LiveTestSession.t()
Link to this function

assert_html(test_session, expected_html)

View Source
Link to this function

assert_page_title(test_session, expected)

View Source
@spec assert_page_title(Heyya.LiveTestSession.t(), String.t() | Regex.t()) ::
  Heyya.LiveTestSession.t()
Link to this function

click(test_session, selector, text \\ nil)

View Source

This method clicks on an element that's selected via selector then renders the result. Finally returning a new LiveTestSession with updated rendered html

This will also assert that there is an element that's specified by the selector

This doesn't follow navigations or redirect.

returns: %Heyya.LiveTestSession{}

Link to this macro

follow(before, to \\ nil)

View Source (macro)
Link to this function

form(test_session, selector, opts)

View Source

Sets the form specified by the selector to a new value.

This doesn't submit the form

returns: %Heyya.LiveTestSession{}

Link to this function

refute_element(test_session, selector, text \\ nil)

View Source
@spec refute_element(Heyya.LiveTestSession.t(), String.t(), String.t() | nil) ::
  Heyya.LiveTestSession.t()
Link to this function

refute_html(test_session, unexpected_html)

View Source
Link to this function

refute_page_title(test_session, unexpected)

View Source
@spec refute_page_title(Heyya.LiveTestSession.t(), String.t() | Regex.t()) ::
  Heyya.LiveTestSession.t()
Link to this macro

start(conn, path)

View Source (macro)

Macro that creates code to start a new LiveTestSession. This takes in a plug connection (Usually from your ConnTest)

Link to this function

submit_form(test_session, selector, opts)

View Source

Submits the form and renders the result of submitting.

This doesn't follow any redirects.

returns: %Heyya.LiveTestSession{}