Skip to content

Support even more CSS selectors #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- Add possibility to test HTML: all, attribute prefix, attribute contains,
attribute ends with, child, and class selectors
- Fix matching mutiple calls for the same selector/function exception

## 4.3.1
Expand Down
9 changes: 9 additions & 0 deletions lib/jquery/assert_select.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def escape_id(selector)

id = selector.gsub('[', '\[')
id.gsub!(']', '\]')
id.gsub!('*', '\*')
id.gsub!('(', '\(')
id.gsub!(')', '\)')
id.gsub!('.', '\.')
id.gsub!('|', '\|')
id.gsub!('^', '\^')
id.gsub!('$', '\$')
id.gsub!('+', "\\\\+")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find why does the plus sign has such strange behavior.

id.gsub!(',', '\,')

id
end
Expand Down
6 changes: 6 additions & 0 deletions test/assert_select_jquery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class AssertSelectJQueryTest < ActiveSupport::TestCase
$('#id').remove();
jQuery("#id").hide();
$("[data-placeholder~=name]").remove();
$("#cart tr:not(.total_line) > *").remove();
$("[href|=\"val\"][href$=\"val\"][href^=\"val\"]").remove();
$("tr + td, li").remove();
JS

setup do
Expand All @@ -32,6 +35,9 @@ def test_target_as_receiver
assert_select 'p', 'something'
end
assert_select_jquery :remove, "[data-placeholder~=name]"
assert_select_jquery :remove, "#cart tr:not(.total_line) > *"
assert_select_jquery :remove, "[href|=\"val\"][href$=\"val\"][href^=\"val\"]"
assert_select_jquery :remove, "tr + td, li"
end

assert_raise Minitest::Assertion, "No JQuery call matches [:show, :some_wrong]" do
Expand Down