Skip to content

Commit

Permalink
Clarify options to LiveViewTest.element (phoenixframework#3389)
Browse files Browse the repository at this point in the history
PR phoenixframework#3250 added more explicit pattern matching to the `element` function,
but didn't handle the missing text filter case.

Closes phoenixframework#3250
  • Loading branch information
SteffenDE authored Aug 15, 2024
1 parent 5992645 commit 32561b4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/phoenix_live_view/test/live_view_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,9 @@ defmodule Phoenix.LiveViewTest do
call(element, {:render_element, :has_element?, element})
end

defguardp is_text_filter(text_filter)
when is_binary(text_filter) or is_struct(text_filter, Regex) or is_nil(text_filter)

@doc """
Checks if the given `selector` with `text_filter` is on `view`.
Expand All @@ -1032,7 +1035,8 @@ defmodule Phoenix.LiveViewTest do
assert has_element?(view, "#some-element")
"""
def has_element?(%View{} = view, selector, text_filter \\ nil) do
def has_element?(%View{} = view, selector, text_filter \\ nil)
when is_binary(selector) and is_text_filter(text_filter) do
has_element?(element(view, selector, text_filter))
end

Expand Down Expand Up @@ -1136,7 +1140,8 @@ defmodule Phoenix.LiveViewTest do
|> element(~s{[href="/foo"][id="foo.bar.baz"]})
|> render() =~ "Increment</a>"
"""
def element(%View{proxy: proxy}, selector, text_filter \\ nil) when is_binary(selector) do
def element(%View{proxy: proxy}, selector, text_filter \\ nil)
when is_binary(selector) and is_text_filter(text_filter) do
%Element{proxy: proxy, selector: selector, text_filter: text_filter}
end

Expand Down

0 comments on commit 32561b4

Please sign in to comment.