DEV Community

Will Ceolin
Will Ceolin

Posted on

1

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)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay