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.
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
@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
1 Like
So happy to hear you are enjoying the book and finding it useful!! Thanks for sharing your feedback