Testing our templates
In order to test our controllers with HTML responses, we will again leverage the Plug.Test
module. Let’s start by creating a test module:
test/example_server_html_eex/controller_test.exs
defmodule ExampleServerHtmlEex.ControllerTest do use ExUnit.Case use Plug.Test describe "GET /greet" do test "responds with an HTML document" do conn = conn(:get, "/greet?greeting=Hola") conn = ExampleServerHtmlEex.Router.call(conn, []) assert conn.status == 200 assert conn.resp_body =~ "<h1>Hola World!</h1>" end end end
In the preceding code, we make a GET
request to /greet
, with the greeting
query parameter set to Hola
. Therefore, we expect the resulting HTML to contain <...