Skip to content

Commit

Permalink
Fix bad button type error reporting.
Browse files Browse the repository at this point in the history
If there are duplicate buttons then Wallaby will incorrectly return an
error saying that the button has a bad type. However, the real error is
that the specified count is incorrect. This commit adds a test for this
case and fixes the underlying bug.
  • Loading branch information
keathley authored and PragTob committed May 13, 2017
1 parent a5210ec commit 3320fd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions integration_test/cases/browser/click_button_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,12 @@ defmodule Wallaby.Integration.Browser.Actions.ClickButtonTest do
test "escapes quotes", %{page: page} do
assert click(page, button("I'm a button"))
end

test "with duplicate buttons", %{page: page} do
assert_raise Wallaby.QueryError, ~r/Expected (.*) 1/, fn ->
page
|> find(css(".duplicate-buttons"))
|> click(button("Duplicate Button"))
end
end
end
4 changes: 4 additions & 0 deletions integration_test/support/pages/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ <h1>Forms</h1>
</label>
</div>

<div class="duplicate-buttons">
<button>Duplicate Button</button>
<button>Duplicate Button</button>
</div>
<script>
setTimeout(function() {
document.querySelector('.js-hidden').style.display = 'block'
Expand Down
2 changes: 1 addition & 1 deletion lib/wallaby/browser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ defmodule Wallaby.Browser do
buttons = all(parent, Query.css("button", [text: query.selector]))

cond do
Enum.any?(buttons) ->
Enum.count(buttons) == 1 && Enum.any?(buttons) ->
{:error, :button_with_bad_type}
true ->
{:ok, query}
Expand Down

0 comments on commit 3320fd7

Please sign in to comment.