germsvel / phoenix_test

MIT License
144 stars 20 forks source link

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

Closed randycoulman closed 4 months ago

randycoulman commented 4 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 4 months ago

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