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.
E.g:
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):
test "put request params" do
conn = build_conn(:get, "/", %{"foo" => "bar"})
assert conn.params == %{"foo" => "bar"}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With