Skip to content

Cookbook: Testing sent requests

Tymon Tobolski edited this page Nov 8, 2018 · 1 revision

See https://github.com/teamon/tesla/issues/195

defmodule ApiTest do      
  use ExUnit.Case                  

  setup do                     
    Tesla.Mock.mock fn             
      %{method: :get} = env ->     
        send self(), {:this_is_request, env} # send request env to self
        %Tesla.Env{}                         
    end          

    :ok     
  end            

  test "issue some request here" do                   
    Api.some_call()

    assert_receive {:this_is_request, %{url: "/some"}}
  end            
end