We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Mocking in Elixir is always a hot topic, mainly because of people coming from different other technologies having different expectation. The most "cannonical" solution, Mox, gives a lot of security with regard to what the fake implementation returns, but requires a bit of a ceremony from the programmer. Other solutions like Mock, Rewire or Bypass offer more ad-hoc mocking, but t the price of the tests heving to be synchronous. Then there's Mimic, which offers ad-hoc mocking and supports async tests.
In this busy area, a new library appeared very recently. It's called Efx and its description does not even mention mocking:
A library to declaratively write testable effects It immediately cought m attention, because it seems to implement what I described as “purity injection” some time ago. As a programmer, you write a default impure implementation of the code, but you mark it as an “effect”. Then in tests you replace a stateful implementation with something more predictable (you “inject purity”) and you can enjoy nice, stable and fast tests.
continue reading on katafrakt.me
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.