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

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
brianokken
Many tasks_proj/tests directories exist in chapters 2, 3, 5 that have tests that use the custom markers smoke and get, which are not decl...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New

Other popular topics Top

AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
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
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
New
PragmaticBookshelf
Programming Ruby is the most complete book on Ruby, covering both the language itself and the standard library as well as commonly used t...
New
hilfordjames
There appears to have been an update that has changed the terminology for what has previously been known as the Taskbar Overflow - this h...
New

Sub Categories: