mercredi 25 octobre 2017

Mock function elixir

I have a function like this

def foo_bar() do
  Enum.reduce_while(
    image_options,
    0,
    fn image_option, _foo ->
      case image_option["destination"] do
        "s3" ->

          case response = Upload.upload_on_s3(foo, bar) do
            {:ok, _} ->
              {:cont, {:ok, "ok"}}
            {:error, _} ->
              {:halt, response}
          end
        _ ->
          {:cont, {:ok, "todo"}}
      end
    end
  )

end

I want to test foo_bar in unit test. How can I mock Upload.upload_on_s3(foo, bar) function?

Aucun commentaire:

Enregistrer un commentaire