One of the default tests checks that a page exists and that the body has a certain string in it:
test "GET /", %{conn: conn} do
conn = get(conn, ~p"/")
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
end
I’d like to write a similar test that only checks if the page exists (the return status is 200). One way to do this is:
test "GET /page", %{conn: conn} do
conn = get(conn, ~p"/page")
assert html_response(conn, 200)
end
The tests indeed fails if the page doesn’t exist, and passes if it does. However, the reason the test fails is that it raises an error. Which feels like bad practice: to use errors for control flow.
I came up with:
test "GET /page", %{conn: conn} do
conn = get(conn, ~p"/page")
assert conn.status == 200
end
But, I feel like Phoenix should have a more idiomatic way to test this.
What’s the best way to perform this test?