[英]How to populate request parameters into a Plug.Conn connection?
I'm trying to test a method that receives a connection of type Plug.Conn but I don't find a way of initializing the connection with the request parameters with the Plug.Conn
API.我正在尝试测试接收类型为Plug.Conn的连接的方法,但我没有找到使用Plug.Conn
API 使用请求参数初始化连接的方法。
Eg:例如:
test "put request params", %{conn: conn} do
# put %{"foo" => "bar"} into the connection params
assert conn.params == %{"foo" => "bar"}
end
Is there any way to set those parameters in the connection?有没有办法在连接中设置这些参数?
Unless you're doing something special in your MyAppWeb.ConnCase
setup that you want to use here, the easiest way would be building a new conn with Phoenix.ConnTest.build_conn/3
(or Plug.Test.conn/3
if you aren't using Phoenix):除非你在MyAppWeb.ConnCase
设置中做一些特别的MyAppWeb.ConnCase
,你想在这里使用,最简单的方法是使用Phoenix.ConnTest.build_conn/3
(或者Plug.Test.conn/3
如果你不是) t 使用凤凰):
test "put request params" do
conn = build_conn(:get, "/", %{"foo" => "bar"})
assert conn.params == %{"foo" => "bar"}
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.