wyrdforge

wyrdforge

Programming Phoenix LiveView B3.0 P276: Assertion in age group filter not working for me

Hi, I am not really sure, if it just an error injected by me somewhere, thus I marked this as question, not as erratum :slight_smile:

The assertion in the testing pipeline on page 276:

test "it filters by age group", %{conn: conn} do
  {:ok, view, _html} = live(conn, "/admin-dashboard")
  view
  |> element("#age-group-form")
  |> render_change(%{"age_group_filter" => "18 and under"})
  |> assert =~ "<title>2.00</title>"
end

seems to never fail for me, even if I put “abcdef” as pattern.

I can get assertion errors , when doing the test this way:

    test "it filters by age group", %{conn: conn} do
      {:ok, view, _html} = live(conn, "/admin-dashboard")
      html =
        view
        |> element("#age-group-form")
        |> render_change(%{"age_group_filter" => "18 and under"})

      assert html =~ "<title>abcdef</title>"
    end

Using a html |> assert =~ "<title>abcdef</title>" also does not fail. Strange, as a simple "Test" |> assert =~ "abc" yields the assertion error, that I would expect.

Edit:
"Test" |> assert =~ "abc" just fails in IEX, when importing ExUnit.Assertions, not when putting this into the live view test. There it gives a success.

Marked As Solved

SophieDeBenedetto

SophieDeBenedetto

Author of Programming Phoenix LiveView

Hey @wyrdforge, thanks for bringing this up! I am in fact able to replicate the issue and it looks like the syntax for this particular test is wrong. The test block should read like this:

test "it filters by age group", %{conn: conn} do
      {:ok, view, _html} = live(conn, "/admin-dashboard")
      params = %{"age_group_filter" => "18 and under"}
        assert view
                |> element("#age-group-form")
                |> render_change(params) =~ "<title>2.00</title>"
    end

Where [assert/1](https://hexdocs.pm/ex_unit/ExUnit.Assertions.html#assert/1) is called with the argument of the logical evaluation of pipeline_results =~ some_outcome. That is because the assert/`` function takes in an argument of some assertion, and our assertion should be “the resulting html from calling our pipeline does contain the given title element”.

The fix will be included in the next Beta release :rocket:

Also Liked

wyrdforge

wyrdforge

@SophieDeBenedetto Thank you for your explanation and the great job you do with the book, in general. All the small (sometimes more confusing, than helpful) pieces of information I gathered before now fall into place and I finally get the big picture, what live views and components are all about and how to put them to work efficiently :smiley:

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
raul
Page 28: It implements io.ReaderAt on the store type. Sorry if it’s a dumb question but was the io.ReaderAt supposed to be io.ReadAt? ...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
patoncrispy
I’m new to Rust and am using this book to learn more as well as to feed my interest in game dev. I’ve just finished the flappy dragon exa...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
gorkaio
root_layout: {PentoWeb.LayoutView, :root}, This results in the following following error: no “root” html template defined for PentoWeb...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1032 17402 381
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New

Sub Categories: