我有/teams
的路线和一条通过mix phx.routes
team_path
的路径。但是我收到undefined function team_path/3
以下是我的测试代码:
describe "create team" do
test "renders team when data is valid", %{conn: conn} do
conn = post(conn, team_path(conn, :create, team: @team_attrs))
assert %{"id" => id} = json_response(conn, 201)["data"]
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, team_path(conn, :create, team: @invalid_attrs))
assert json_response(conn, 400)["errors"] != %{}
end
end
附加信息:
- 凤凰城 1.4 测试 版
- phoenix_swagger已安装
- 它是一个 API,因此一切都在范围内
/api
我认为 POST 调用的有效负载位于post()
函数中,而您将其放在team_path
助手中。你能试试吗:
conn = post(conn, team_path(conn, :create), %{team: @team_attrs})
文档链接以供参考:
https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#post/3