Running live view tests that calls get_connect_params raise error

You are trying to write a unit test for your LiveView mount, which is not recommended because in your code you do not invoke the mount callback directly. Instead as German points out in the talk you want to test the lifecycle of your LiveView.

For instance, you can use put_connect_params/2 to simulate the client connection with params:

defmodule MyAppWeb.MyFileTest do
  use MyAppWeb.ConnCase

  test "connect params", %{conn: conn} do
    # Simulate client behaviour
    conn = put_connect_params(conn, %{"timezone" => "America/Chicago"})

    {:ok, view, _html} = live(conn, "/")

    # Assert something about the _rendered output_
    assert render(view) =~ "CDT"
  end
end

Note that you can’t trust client-side data without some kind of validation. In the above example I am asserting on a computed timezone value to imply that some validation took place in order to arrive at the rendered output.

Note also that such an assertion only works if you are rendering the value somewhere on the template. Similar to traditional Controller tests, we want to assert on the side effects of the controller request/response flow as opposed to the state of the things directly after invoking the action function.