2
votes

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
1

1 Answers

3
votes

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