#development #elixir #phoenix #reading-list #testing

🔗 Start with unit tests on LiveView modules
dev.to

I have been working with Phoenix and LiveView in a full-time position for around 18 months now, and most recently LiveView started to become something that I do often.

At the beginning I was unsure about my coding and whether I was doing it correctly on the LiveView modules. Should I keep logic there? Should I create utility functions on the LiveView module? Should I make an external module to handle that?

After these months what use as a rule of thumb is: to deal with the LiveView module the same way I deal with a controller. That means I try to keep the module as clean as possible and only with the needed actions, such as mounting, handling callbacks, and assigning data to the socket.

I try to avoid adding business logic related to product on these modules cause this logics usually require more testing and testing it using LiveView can be tricky and not consider all scenarios.

This will make not only the code simple but also the effort to test tend to be very straightforward.

When checking the LiveView module test, your tests should be readable in a way that basically tells you how the user interacts with the page flow.

continue reading on dev.to

⚠️ This post links to an external website. ⚠️