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.:
%Phoenix.LiveView.Rendered{
dynamic: #Function<0.64041902/1 in PeanutButterWeb.PageView."hello.html"/1>,
fingerprint: 29760870404026531075951007545402085092,
root: true,
static: ["<p>Hello, Kurt</p>"]
}
This is also true, even if I’m rendering from a plain view.
Is there a simple way to convert this struct to plain html?
Thanks