Skip to content

Commit

Permalink
Allow multiple matching elements in assert_has (#20)
Browse files Browse the repository at this point in the history
Fixes #18

The docs for assert_has say "It'll raise an error if no elements are found, but it will not raise if more than one matching element is found."

But I'm seeing that an assert_has with multiple matching elements is raising a CaseClauseError when it gets back a {:found_many, ...} tuple.

This commit fixes that by adding the necessary clause.
  • Loading branch information
randycoulman authored Feb 10, 2024
1 parent 6eb464c commit ac0e167
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/phoenix_test/assertions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ defmodule PhoenixTest.Assertions do
{:found, _found} ->
assert true

{:found_many, _found} ->
assert true

{:not_found, []} ->
raise AssertionError,
message: """
Expand Down
6 changes: 6 additions & 0 deletions test/phoenix_test/assertions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ defmodule PhoenixTest.AssertionsTest do
|> assert_has("li", "Aragorn")
end

test "succeeds if more than one element matches selector and text", %{conn: conn} do
conn
|> visit("/page/index")
|> assert_has(".multiple_links", "Multiple links")
end

test "succeeds if text difference is only a matter of truncation", %{conn: conn} do
conn
|> visit("/page/index")
Expand Down

0 comments on commit ac0e167

Please sign in to comment.