I am resurrecting this topic to share that you can test chunk responses if you follow the documentation for chunk. The test adapter collects chunks and updates the response body.
defp send_csv_response(%Plug.Conn{} = conn, _) do
{:ok, %Plug.Conn{state: :chunked} = conn} =
conn
|> put_resp_content_type("text/csv")
|> put_resp_header("content-disposition", ~s|attachment; filename="foo.csv"|)
|> send_chunked(:ok)
Enum.reduce_while(["a", "b", "c"], conn, fn data, conn ->
case chunk(conn, data) do
{:ok, conn} -> {:cont, conn}
{:error, :closed} -> {:halt, conn}
end
end)
end
And in tests
test "chunked response", %{conn: conn} do
%Plug.Conn{state: :chunked} = response = conn |> get(page_path(conn, :send_csv_response)
content = response(response, 200)
assert content == "abc"
end






















