You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've read the documentation about transport_error/2 and maybe I'm understanding it wrong.
Following the docs as closely as I can, here's my (unexpectedly) failing test:
test"returns the error when the request fails"doReq.Test.stub(MyApp.MyModule,fnconn->Req.Test.transport_error(conn,:some_error)end)assert{:error,:some_error}=my_get_function()end
The test fails not because the match fails, but because my_get_function/0 raises:
But I'm not using Req.get!/2. I'm using Req.get/2 just like the docs suggest.
Here's my_get_function/0:
@docfalsedefmy_get_function()do:my_app|>Application.get_env(MyApp.MyModule,[])|>then(&Req.get(@url,&1))# `get`, and not `get!`|>casedo{:ok,%Req.Response{status: 200,body: body,headers: headers}}->{:ok,body,headers}{:ok,response}->{:error,response}error->errorendend
Is there something I'm missing? Is this intended behavior?
The text was updated successfully, but these errors were encountered:
Thank you for the report, we definitely need to improve the error message.
The idea was you can only call transport_error/1 with errors that can happen in production so your test is more realistic. So transport_error(conn, :timeout) works but transport_error(conn, :timeout_typo) does not.
It would also be nice to know which atoms we're allowed to inject there.
:timeout isn't always that handy: I might want to retry in production, but I'd like to avoid that specific error case when testing (else, I must wait several seconds).
I've read the documentation about transport_error/2 and maybe I'm understanding it wrong.
Following the docs as closely as I can, here's my (unexpectedly) failing test:
The test fails not because the match fails, but because
my_get_function/0
raises:But I'm not using
Req.get!/2
. I'm usingReq.get/2
just like the docs suggest.Here's
my_get_function/0
:Is there something I'm missing? Is this intended behavior?
The text was updated successfully, but these errors were encountered: