Skip to content

Commit

Permalink
Surface 'text' condition in css query error message (#714)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderhoop authored Nov 10, 2022
1 parent c2e9837 commit ae20b0c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/wallaby/query/error_message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,14 @@ defmodule Wallaby.Query.ErrorMessage do
"'#{name}' with value '#{value}'"
end

def selector(%Query{selector: selector}) do
"'#{selector}'"
def selector(%Query{selector: selector, conditions: conditions}) do
text = with_text(conditions[:text])
"'#{selector}'#{text}"
end

defp with_text(nil), do: ""
defp with_text(text), do: " and contained the text '#{text}'"

defp with_index(:all), do: nil
defp with_index(at), do: " and return element at index #{at}"

Expand Down
28 changes: 28 additions & 0 deletions test/wallaby/query/error_message_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,34 @@ defmodule Wallaby.Query.ErrorMessageTest do
alias Wallaby.Query.ErrorMessage

describe "message/1" do
test "inclusion of binary 'text' condition when present in css query" do
message =
Query.css(".lcp-value", text: "322ms")
|> Map.put(:result, [])
|> ErrorMessage.message(:not_found)
|> format

assert message ==
format("""
Expected to find 1 visible element that matched the css '.lcp-value' and contained the text '322ms', but 0 visible
elements were found.
""")
end

test "no reference of 'text' condition when it isn't specified" do
message =
Query.css(".lcp-value")
|> Map.put(:result, [])
|> ErrorMessage.message(:not_found)
|> format

assert message ==
format("""
Expected to find 1 visible element that matched the css '.lcp-value', but 0 visible
elements were found.
""")
end

test "when the results are more than the expected count" do
message =
Query.css(".test", count: 1)
Expand Down

0 comments on commit ae20b0c

Please sign in to comment.