混合测试后未定义的_path

时间:2018-10-11 02:58:44

标签: elixir phoenix-framework

我有/teams的路线和经过team_path的路线mix phx.routes。但是我收到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-beta
  • 安装了phoenix_swagger
  • 具有API,因此所有内容都在/api范围内

1 个答案:

答案 0 :(得分:0)

我认为POST调用的有效负载在post()函数中,而您已经将它放入了team_path帮助程序中。您可以尝试:

conn = post(conn, team_path(conn, :create), %{team: @team_attrs})

链接到文档以供参考:

https://hexdocs.pm/phoenix/Phoenix.ConnTest.html#post/3