我进行了以下测试,其中使用了先前请求中的数据:
test "renders user when data is valid", %{conn: conn} do
conn = post conn, user_path(conn, :create), user: @create_attrs
assert %{"jwt" => jwt} = json_response(conn, 201)["data"]
conn = get (conn |> put_req_header("Authorization", "Bearer #{jwt}")), user_path(conn, :show)
assert %{"id" => _, "email" => "some email", "password_hash" => "some password_hash"} = json_response(conn, 201)["data"]
end
但是此测试失败并显示:
** (Plug.Conn.AlreadySentError) the response was already sent
如何在这里重用conn
?
答案 0 :(得分:1)
使用原始的conn
从GET
请求中获得期望的结果(我将{{1}的conn
替换为conn1
:
POST