While executing ExUnit.start
, in each case, I prepare mocks by meck
like bellow
defmodule MyModule.FooTest do
use ExUnit.Case, async: false # explicitly sync
import :meck
alias MyModule.Foo
alias MyModule.Baz # to be mocked
test "call_baz" do
expect(Baz, :some_async_method, [
{[], :meck.val(Task.async(fn -> %{"name" => "otiai10"} end)},
])
assert Foo.call_baz() == %{"name" => "otiai10"}
end
end
But it returns {"name" => "otiai200"}
, because Baz.some_async_method
is mocked by another test with returning {"name" => "otiai200"}
.
It is certainly the response of what mocked in another test cases. (They are also given async: false
option in their use
statement)
What is the problem, async: false
option doesn't work? or is mocking Task.async
not recommended? Or do I do any basic mistakes?
Thank you