Write Tests for a LiveView
Let's test our LiveView with some basic tests.
We'll cover the following
Testing LiveView
LiveView, like Channels, provides test helpers that allow us to write meaningful tests for our LiveView module quickly. The Phoenix.LiveViewTest
module offers all the helpers we need to start writing tests.
Our LiveView is pretty simple because it doesn’t respond to front-end events. Our tests will be basic because of this. We’ll ensure that ProductLiveView
mounts and renders the correct HTML.
We’ll need to add a test dependency to our mix.exs
file to get started. LiveViewTest
uses Floki
to parse HTML, so let’s add that.
Get hands-on with 1400+ tech skills courses.