Reputation: 20815
I have a view module in my phoenix application that contains render_footer/1
. How would I go about testing this function using EXUnit?
defmodule Lorem.LayoutView do
use Lorem.Web, :view
def render_footer(conn) do
render __MODULE__, "footer.html", conn: conn
end
end
defmodule Lorem.LayoutViewTest do
use Lorem.ConnCase, async: true
test "render_footer" do
flunk "Not implemented!"
end
end
Upvotes: 2
Views: 1389
Reputation: 8100
You can call Phoenix.View.render_to_string
. Also keep in mind that your templates are all precompiled as render/2
calls, so I would simply call
render LayoutView, "footer.html", assigns
Instead of the render_footer
function, unless you need to do a bunch of assigns prep. For testing, you can do:
import Phoenix.View
test "render_footer" do
render_to_string(Lorem.LayoutView, "footer.html", ..) =~ "copyright"
end
Upvotes: 3