noelHan
Cannot mock Process module with Mock.with_mocks macro
I try mock library for my tests. But I cannot mock function with it
This is my test code
test "test" do
with_mock Process, send_after: fn _, _, _ -> :ok end do
assert Process.send_after(self(), :message, 5_000) == :ok
end
end
and I notice that Process module is not mocked. with_mock works well with other modules but it did not work with Process. Why this happens and how can I solve this?
Thanks ![]()
Marked As Solved
al2o3cr
I suspect your difficulty is related to this note in the docs for Process.send_after:
Inlined by the compiler.
Replacing the Process module won’t do much if the call to Process.send_after has already been compiled down to :erlang.send_after.
Also Liked
noelHan
Sorry for confusing you. That’s not my real test code. It’s just sample code to explain my problem. And I can mock modules like String, IO. So I guess it would be work with Process too.
hst337
You can use Patch alongside any other Mock project. Most of the mocks in Elixir are written in a way of explicit dependency injection, while Patch actually changes the module code in very efficient way.
Ever since I found Patch, I’ve stopped using Mex, Mox, Protomox and other dependency injection tooling







