...
/Testing Server-rendered HTML Applications
Testing Server-rendered HTML Applications
Learn how to test server-rendered HTML endpoints.
We'll cover the following...
Testing server-rendered HTML endpoints is very similar to testing JSON endpoints, but the response is an HTML document instead of JSON.
Controller
We’ll write tests for the user controller that handles the server-rendered HTML endpoints. Let’s start by looking at the controller code that we’ll be testing:
Press + to interact
#file path -> lib/not_skull_web/controllers/user_controller.ex#add this code at the indicated place mentioned in comments of lib/not_skull_web/#controllers/user_controller.ex in the playground widgetdefmodule NotSkullWeb.UserController douse NotSkullWeb, :controlleralias NotSkull.Accountsalias NotSkull.Accounts.Useralias NotSkull.ExternalServices.Emaildef new(conn, _params) douser = User.create_changeset(%{})render(conn, "new.html", changeset: user)enddef create(conn, %{"user" => user_params}) docase Accounts.create_user(user_params) do{:ok, user} ->Email.send_welcome(user)conn|> put_session(:user_id, user.id)|> put_flash(:info, "Your account was created successfully!")|> redirect(to: Routes.user_path(conn, :show, user)){:error, %Ecto.Changeset{} = changeset} ->render(conn, "new.html", changeset: changeset)endendend
This code is a controller that, under the hood, calls to the same context module as the JSON controller we’ve already tested. Our testing will focus on the two endpoints that call the new
and create
controller acti ...
...