QUnit Test for jQuery Ticket 7010
Problems on nested selectors
by jitter
HTML
<script src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<link rel="stylesheet" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css">
<a href="http://docs.jquery.com/Qunit">New to Qunit? Check the documentation</a>
<h1 id="qunit-header">QUnit test case template</h1>
<!-- no modification needed on the following line -->
<h2 id="qunit-banner"></h2><h2 id="qunit-userAgent"></h2><ol id="qunit-tests"></ol>
<div id="qunit-fixture">
<ul id="ul1">
<li id="li1">this is some text 1</li>
<li id="li2">
<p id="p1">this is some paragraph 2</p>
</li>
<li id="li3">
<p id="p2">this is
<span id="span1">some
<a href="#" id="a1">paragraph</a>
</span>
</p>
</li>
</ul>
</div>
JavaScript
$(function() {
module(":not(:has(:has(*))) fails");
test(":has(:has(*))", 1, function() {
t( "Grandchildren test", "#qunit-fixture :has(:has(*))", [ "ul1", "li3", "p2" ] );
});
test(":not(:has(*))", 1, function() {
t( "No children test", "#qunit-fixture :not(:has(*))", [ "li1", "p1", "a1" ] );
});
test(":not(:has(:has(*))", 1, function() {
raises( function() {
t( "Invalid selector test (missing closing brace)", "#qunit-fixture :not(:has(:has(*))", [ "#impossible" ] );
}, "An invalid selector is passed in. This should raise an exception" );
});
test(":not(:has(:has(*)))", 1, function() {
t( "No grandchildren test", "#qunit-fixture :not(:has(:has(*)))", [ "li1", "li2", "p1", "span1", "a1" ] );
});
});
// -------------------------------------------------
/* stolen from jQuery's testinit.js */
/**
* Returns an array of elements with the given IDs, eg.
* @example q("main", "foo", "bar")
* @result [<div id="main">, <span id="foo">, <input id="bar">]
*/
function q() {
var r = [];
for ( var i = 0; i < arguments.length; i++ ) { r.push( document.getElementById( arguments[i] ) ); }
return r;
}
/**
* Asserts that a select matches the given IDs * @example t("Check for something", "[a]", ["foo", "baar"]);
* @result returns true if "[a]" returns two elements with the IDs 'foo' and 'baar'
*/
function t(a,b,c) {
var f = jQuery(b).get(), s = "";
for ( var i = 0; i < f.length; i++ ) { s += (s && ",") + '"' + f[i].id + '"'; }
deepEqual(f, q.apply(q,c), a + " (" + b + ")");
}