germsvel / phoenix_test

PhoenixTest provides a unified way of writing feature tests -- regardless of whether you're testing LiveView pages or static (non-LiveView) pages.
https://hex.pm/packages/phoenix_test
MIT License
181 stars 23 forks source link

assert_has/3 on page title does exact matching by default #64

Closed randycoulman closed 7 months ago

randycoulman commented 7 months ago

By default assert_has does substring matching unless exact: true is specified. But assert_has(session, "title", "some page title") always does exact string matching. This is surprising given how that function works with all other elements.

It's especially annoying when using a .live_title component with a prefix or suffix, because LiveView seems to include a bunch of whitespace (newlines and extra spaces) depending on the formatting in root.html.heex around where the @page_title assign is used.

For example, I have this in my root.html.heex:

    <.live_title suffix=" | My App">
      <%= assigns[:page_title] || "Home" %>
    </.live_title>

When I do assert_has(session, "title", "Title"), I get the following error:

Expected title to be "Title" but got "\nTitle\n     | My App"
germsvel commented 7 months ago

Thanks @randycoulman! I noticed this too and had it in my list of to-dos. PR #65 should take care of it.