Greetings Phoenix LiveView Wizards! ????
Context
We have a basic LiveView counter app: https://github.com/dwyl/phoenix-liveview-counter-tutorial
The code is very simple: /live/counter.ex
The App works as expected, see: https://live-view-counter.herokuapp.com
The test file is: test/live_view_counter_web/live/counter_test.exs
We are stuck with trying to invoke the handle_info/2
function in a test.
So we have code in our project that is untested. Which is undesirable.
See: https://codecov.io/gh/dwyl/phoenix-liveview-counter-tutorial/src/master/lib/live_view_counter_web/live/counter.ex
We have read through the official docs https://hexdocs.pm/phoenix_live_view/Phoenix.LiveViewTest.html
but have not been able to understand how to do it. What are we missing?
We really want to use LiveView
in our "real" projects, but we want to ensure that our LiveView
apps are fully tested.
Question
How do we write a test to invoke the handle_info/2
function?
handle_event/3
function. But from re-reading the docs, it appears we do not invoke the function directly rather it is invoked indirectly by therender_click(view, :inc)
👍(thank you for helping us come to this realisation ...) – nelsonichandle_event/3
is a callback for the message arrived to the LV process, which means one does not ever want to test it via direct call. – Aleksei Matiushkinhandle_info/2
function. – nelsonic