DEV Community

Will Ceolin
Will Ceolin

Posted on

Unit testing a page title on Phoenix LiveView

TL;DR:

assert page_title(lv) =~ "my page title"
Enter fullscreen mode Exit fullscreen mode

Phoenix LiveView has a live_title/1 component that allows us to easily update a page title and see those changes reflect in the browser.

They also have a page_title/1 function to test if your page title was updated using the page_title assign.

You can use it to make sure you're assigning a page_title to your pages:

def mount(_params, _session, socket) do
  {:ok, assign(socket, :page_title, "My page title")}
end
Enter fullscreen mode Exit fullscreen mode

Top comments (0)