Integration Testing LiveView Interactions

Learn how to perform integration testing on a LiveView component in this lesson.

Where unit tests check isolated bits of code, integration tests verify the interactions between parts of a system. In this lesson, we’ll write an integration test that validates interactions within a single LiveView. We’ll write both tests without any JavaScript. This statement should get some attention from anyone used to the overhead of bringing in an external JavaScript dependency to write integration tests.

We don’t need JavaScript to test LiveView!

We’ll use the LiveViewTest module’s special LiveView testing functions to simulate LiveView connections without a browser. Our tests can mount and render LiveViews, trigger events, and then execute assertions against the rendered view. That’s the whole LiveView lifecycle.

We might have concerns about leaving JavaScript untested but remember, the JavaScript that supports LiveView is part of the LiveView framework itself, so we also don’t have to leverage JavaScript to test our LiveViews. We can trust that the JavaScript in the framework does what it’s supposed to do, and focus our attention on testing the specific behaviors and features that we built into our own LiveView, in pure Elixir.

As a result, the integration tests for LiveView are quick and easy to write and they run fast and concurrently.

Let’s write some tests.

Get hands-on with 1400+ tech skills courses.