-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing requests #195
Comments
You can return the request in mock (fn env -> env end) but it will be processed by middleware stack as response.
The alternative is to send a message to current process - https://twitter.com/iteamon/status/851375743284244481?s=20
…On 24 Mar 2018, 10:01 +0100, Wilberto Morales ***@***.***>, wrote:
Hello, I'm looking for a way to test against the request sent by a module. My initial intuition was to capture the request during the mock but I'm having trouble doing it in a clean way.
defmodule ApiTest do
use ExUnit.Case
setup do
Tesla.Mock.mock fn
%{method: :get} = env ->
# capture request env here
%Tesla.Env{}
end
{:ok}
end
test "issue some request here" do
Api.get("")
assert request.query == [query: "hello world", token: "12345"]
end
end
My second intuition is to create a middleware that pushes the untouched request at the beginning of the pipeline into somewhere I can read from in the test.
I tried using a global variable but couldn't figure out how to do that in elixir but, I didn't spend too much time toying with that idea because then tests would have to always run serially.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
In this case you don’t even need to register the process since Tesla mock runs in the same process so just
|
Thank you very much @teamon, I went with sending a message to self. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I'm looking for a way to test against the request sent by a module. My initial intuition was to capture the request during the mock but I'm having trouble doing it in a clean way.
My second intuition is to create a middleware that pushes the untouched request at the beginning of the pipeline into somewhere I can read from in the test.
I tried using a global variable but couldn't figure out how to do that in elixir but, I didn't spend too much time toying with that idea because then tests would have to always run serially.
The text was updated successfully, but these errors were encountered: