Phoenix unit test how to check if connection object is redirected to particular path?

Viewed 165

Let's say I have a controller action some_action/2 which redirects to /a-path. I need to write a unit test which asserts if the connection is redirected to /a-path. How to do that in Pheonix.

1 Answers

Use redirected_to function to assert if the connection is redirected to a particular path, as the following example.

   test "redirects to the path /a-path", %{conn: conn, user: user} do
      new_conn = some_action(conn, %{})
      assert redirected_to(new_conn) == "/a-path"
    end
Related