
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
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
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
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /react-native
- /v
- /wasm
- /django
- /security
- /nodejs
- /centos
- /rails
- /haskell
- /fable
- /gleam
- /js
- /swift
- /deno
- /tailwind
- /assemblyscript
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /c-plus-plus
- /preact
- /flutter
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /emacs
- /nim
- /vuejs
- /nerves
- /elm