Usually in tests of my views, I have used safe_to_string() to convert a returned :safe tuple to HTML that I can assert on. For example:
test "greets the user" do
user = %{name: "Kurt"}
html = MyView.render("some_template.html", user: user) |> Phoenix.HTML.safe_to_string()
assert html =~ "Hello, Kurt"
end
However, if the template is a .heex file, this no longer works because the return struct is a %Phoenix.LiveView.Rendered{} struct, e.g.:
Okay, here’s what I found after digging around for a while:
test "greets the user" do
user = %{name: "Kurt"}
html = MyView.render("some_template.html", user: user)
|> Phoenix.HTML.Safe.to_iodata()
|> IO.iodata_to_binary()
assert html =~ "Hello, Kurt"
end
Will give the returned HTML as string, ready for assertions.
but that what I was asking, because we have no views now, what’s the appropriate code, I am new to phx so without seeing any concrete code I couldn’t imagine what it should look like
Thank you for the suggestion, I know about liveview and I will look at it when I am ready, for now I just have a specific use case to send the html that way
from your output I see that tags are replaced by < and > how I can only stripes the tags coming from the assigns, as the static tags in the template are already safe