MoxInject (mox_inject v0.1.1)
Maps between modules, the behaviours they implement, and the modules which are substituted for them in the test environment.
use MoxInject do
alias MODULE, as: @ATTR
...
end
This will assign each dependency, or its test substitute, to the given module attribute.
We usually prefer to use the alias from MoxInject
as that has our
mocked functions. However, if we need to use the module as a type such as in
specs, default arguments and new structures, we need to use the original alias.
In this case, we can have two aliases for the same module in the same file, one is used for the type references and the other is used for the mocked function calls. For instance, we can have the following:
alias Phoenix.LiveView.JS
use MoxInject do
alias Phoenix.LiveView.JS, as: @js
end
defp hide_modal(js \ %JS{}, selector) do
js
|> @js.hide(...)
end
Summary
Functions
Link to this function