diff --git a/lib/wallaby/query/error_message.ex b/lib/wallaby/query/error_message.ex index e52abf08..01f11745 100644 --- a/lib/wallaby/query/error_message.ex +++ b/lib/wallaby/query/error_message.ex @@ -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}" diff --git a/test/wallaby/query/error_message_test.exs b/test/wallaby/query/error_message_test.exs index 6140044f..5fad9944 100644 --- a/test/wallaby/query/error_message_test.exs +++ b/test/wallaby/query/error_message_test.exs @@ -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)