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:

Popular Prag Prog topics Top

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
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
fynn
This is as much a suggestion as a question, as a note for others. Locally the SGP30 wasn’t available, so I ordered a SGP40. On page 53, ...
New
brunogirin
When I run the coverage example to report on missing lines, I get: pytest --cov=cards --report=term-missing ch7 ERROR: usage: pytest [op...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
AstonJ
Or looking forward to? :nerd_face:
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
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
DevotionGeo
The V Programming Language Simple language for building maintainable programs V is already mentioned couple of times in the forum, but I...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New

Latest in PragProg

View all threads ❯