That won’t test anything since send/2
returns the argument, so this assertion does not exercise any handling in the LV.
You also do not want to unit test the callbacks as that is very brittle and does not exercise the stateful LV. Aside: I also never unit tests GenServer’s in this way. For your test, you can send the message, and then assert the rendered LV content is what you expect after it experiences the side effects. This works because LiveViewTest.render/1
sends a message to the LV process to synchronize with it, which guarantees it has already processed the send:
test "handle_info/2", %{conn: conn} do
{:ok, view, disconnected_html} = live(conn, "/")
assert disconnected_html =~ "Count: 0"
assert render(view) =~ "Count: 0"
send(view.pid, %{payload: %{ val: 1 }})
assert render(view) =~ "Count: 1"
end