traversing.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. module("traversing", { teardown: moduleTeardown });
  2. test( "find(String)", function() {
  3. expect( 1 );
  4. equal( jQuery("#foo").find(".blogTest").text(), "Yahoo", "Basic selector" );
  5. });
  6. test( "find(String) under non-elements", function() {
  7. expect( 2 );
  8. var j = jQuery("#nonnodes").contents();
  9. equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
  10. equal( j.find("div").addBack().length, 3, "Check node,textnode,comment to find zero divs, but preserves pushStack" );
  11. });
  12. test( "find(leading combinator)", function() {
  13. expect( 4 );
  14. deepEqual( jQuery("#qunit-fixture").find("> div").get(), q( "foo", "nothiddendiv", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest", "fx-test-group" ), "find child elements" );
  15. deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q( "foo", "moretests" ), "find child elements" );
  16. deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q( "sndp", "en", "sap" ), "find child elements" );
  17. deepEqual( jQuery("#siblingTest, #siblingfirst").find("+ *").get(), q( "siblingnext", "fx-test-group" ), "ensure document order" );
  18. });
  19. test( "find(node|jQuery object)", function() {
  20. expect( 12 );
  21. var $foo = jQuery("#foo"),
  22. $blog = jQuery(".blogTest"),
  23. $first = jQuery("#first"),
  24. $two = $blog.add( $first ),
  25. $fooTwo = $foo.add( $blog );
  26. equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" );
  27. equal( $foo.find( $blog[ 0 ] ).text(), "Yahoo", "Find with blog node" );
  28. equal( $foo.find( $first ).length, 0, "#first is not in #foo" );
  29. equal( $foo.find( $first[ 0 ]).length, 0, "#first not in #foo (node)" );
  30. ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" );
  31. ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" );
  32. ok( $fooTwo.find( $blog[ 0 ] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" );
  33. equal( $two.find( $foo ).length, 0, "Foo is not in two elements" );
  34. equal( $two.find( $foo[ 0 ] ).length, 0, "Foo is not in two elements(node)" );
  35. equal( $two.find( $first ).length, 0, "first is in the collection and not within two" );
  36. equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" );
  37. equal( $two.find( $foo[ 0 ] ).addBack().length, 2, "find preserves the pushStack, see #12009" );
  38. });
  39. test("is(String|undefined)", function() {
  40. expect(23);
  41. ok( jQuery("#form").is("form"), "Check for element: A form must be a form" );
  42. ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" );
  43. ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" );
  44. ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" );
  45. ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" );
  46. ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
  47. ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" );
  48. ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
  49. ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" );
  50. ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
  51. ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" );
  52. ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" );
  53. ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" );
  54. ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" );
  55. ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" );
  56. ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" );
  57. ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" );
  58. ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" );
  59. ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" );
  60. // test is() with comma-separated expressions
  61. ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
  62. ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
  63. ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
  64. ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-separated; Check for lang attribute: Expect en or de" );
  65. });
  66. test("is() against non-elements (#10178)", function() {
  67. expect(14);
  68. var label, i, test,
  69. collection = jQuery( document ),
  70. tests = [ "a", "*" ],
  71. nonelements = {
  72. text: document.createTextNode(""),
  73. comment: document.createComment(""),
  74. document: document,
  75. window: window,
  76. array: [],
  77. "plain object": {},
  78. "function": function() {}
  79. };
  80. for ( label in nonelements ) {
  81. collection[ 0 ] = nonelements[ label ];
  82. for ( i = 0; i < tests.length; i++ ) {
  83. test = tests[ i ];
  84. ok( !collection.is( test ), label + " does not match \"" + test + "\"" );
  85. }
  86. }
  87. });
  88. test("is(jQuery)", function() {
  89. expect(19);
  90. ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" );
  91. ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" );
  92. ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" );
  93. ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" );
  94. ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
  95. ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
  96. ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" );
  97. ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" );
  98. ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" );
  99. ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" );
  100. ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" );
  101. ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" );
  102. ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" );
  103. // Some raw elements
  104. ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" );
  105. ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" );
  106. ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" );
  107. ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" );
  108. ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" );
  109. ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" );
  110. });
  111. test("is() with :has() selectors", function() {
  112. expect(6);
  113. ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" );
  114. ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" );
  115. ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" );
  116. ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" );
  117. ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" );
  118. ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" );
  119. });
  120. test("is() with positional selectors", function() {
  121. expect(27);
  122. var
  123. posp = jQuery(
  124. "<p id='posp'><a class='firsta' href='#'><em>first</em></a>" +
  125. "<a class='seconda' href='#'><b>test</b></a><em></em></p>"
  126. ).appendTo( "#qunit-fixture" ),
  127. isit = function( sel, match, expect ) {
  128. equal(
  129. jQuery( sel ).is( match ),
  130. expect,
  131. "jQuery('" + sel + "').is('" + match + "')"
  132. );
  133. };
  134. isit( "#posp", "p:last", true );
  135. isit( "#posp", "#posp:first", true );
  136. isit( "#posp", "#posp:eq(2)", false );
  137. isit( "#posp", "#posp a:first", false );
  138. isit( "#posp .firsta", "#posp a:first", true );
  139. isit( "#posp .firsta", "#posp a:last", false );
  140. isit( "#posp .firsta", "#posp a:even", true );
  141. isit( "#posp .firsta", "#posp a:odd", false );
  142. isit( "#posp .firsta", "#posp a:eq(0)", true );
  143. isit( "#posp .firsta", "#posp a:eq(9)", false );
  144. isit( "#posp .firsta", "#posp em:eq(0)", false );
  145. isit( "#posp .firsta", "#posp em:first", false );
  146. isit( "#posp .firsta", "#posp:first", false );
  147. isit( "#posp .seconda", "#posp a:first", false );
  148. isit( "#posp .seconda", "#posp a:last", true );
  149. isit( "#posp .seconda", "#posp a:gt(0)", true );
  150. isit( "#posp .seconda", "#posp a:lt(5)", true );
  151. isit( "#posp .seconda", "#posp a:lt(1)", false );
  152. isit( "#posp em", "#posp a:eq(0) em", true );
  153. isit( "#posp em", "#posp a:lt(1) em", true );
  154. isit( "#posp em", "#posp a:gt(1) em", false );
  155. isit( "#posp em", "#posp a:first em", true );
  156. isit( "#posp em", "#posp a em:last", true );
  157. isit( "#posp em", "#posp a em:eq(2)", false );
  158. ok( jQuery("#option1b").is("#select1 option:not(:first)"), "POS inside of :not() (#10970)" );
  159. ok( jQuery( posp[0] ).is("p:last"), "context constructed from a single node (#13797)" );
  160. ok( !jQuery( posp[0] ).find("#firsta").is("a:first"), "context derived from a single node (#13797)" );
  161. });
  162. test("index()", function() {
  163. expect( 2 );
  164. equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" );
  165. equal( jQuery("<div/>").index(), -1, "Node without parent returns -1" );
  166. });
  167. test("index(Object|String|undefined)", function() {
  168. expect(16);
  169. var elements = jQuery([window, document]),
  170. inputElements = jQuery("#radio1,#radio2,#check1,#check2");
  171. // Passing a node
  172. equal( elements.index(window), 0, "Check for index of elements" );
  173. equal( elements.index(document), 1, "Check for index of elements" );
  174. equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" );
  175. equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" );
  176. equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" );
  177. equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" );
  178. equal( inputElements.index(window), -1, "Check for not found index" );
  179. equal( inputElements.index(document), -1, "Check for not found index" );
  180. // Passing a jQuery object
  181. // enabled since [5500]
  182. equal( elements.index( elements ), 0, "Pass in a jQuery object" );
  183. equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" );
  184. equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" );
  185. // Passing a selector or nothing
  186. // enabled since [6330]
  187. equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" );
  188. equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" );
  189. equal( jQuery("#radio2").index("#form input[type='radio']") , 1, "Check for index within a selector" );
  190. equal( jQuery("#form input[type='radio']").index( jQuery("#radio2") ), 1, "Check for index within a selector" );
  191. equal( jQuery("#radio2").index("#form input[type='text']") , -1, "Check for index not found within a selector" );
  192. });
  193. test("filter(Selector|undefined)", function() {
  194. expect(9);
  195. deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
  196. deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
  197. deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
  198. deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object");
  199. deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object");
  200. deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object");
  201. deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object");
  202. // using contents will get comments regular, text, and comment nodes
  203. var j = jQuery("#nonnodes").contents();
  204. equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
  205. equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
  206. });
  207. test("filter(Function)", function() {
  208. expect(2);
  209. deepEqual( jQuery("#qunit-fixture p").filter(function() {
  210. return !jQuery("a", this).length;
  211. }).get(), q("sndp", "first"), "filter(Function)" );
  212. deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length; }).get(), q("sndp", "first"), "filter(Function) using arg" );
  213. });
  214. test("filter(Element)", function() {
  215. expect(1);
  216. var element = document.getElementById("text1");
  217. deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" );
  218. });
  219. test("filter(Array)", function() {
  220. expect(1);
  221. var elements = [ document.getElementById("text1") ];
  222. deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
  223. });
  224. test("filter(jQuery)", function() {
  225. expect(1);
  226. var elements = jQuery("#text1");
  227. deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" );
  228. });
  229. test("filter() with positional selectors", function() {
  230. expect(19);
  231. var filterit = function(sel, filter, length) {
  232. equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" );
  233. };
  234. jQuery( "" +
  235. "<p id='posp'>" +
  236. "<a class='firsta' href='#'>" +
  237. "<em>first</em>" +
  238. "</a>" +
  239. "<a class='seconda' href='#'>" +
  240. "<b>test</b>" +
  241. "</a>" +
  242. "<em></em>" +
  243. "</p>" ).appendTo( "#qunit-fixture" );
  244. filterit( "#posp", "#posp:first", 1);
  245. filterit( "#posp", "#posp:eq(2)", 0 );
  246. filterit( "#posp", "#posp a:first", 0 );
  247. // Keep in mind this is within the selection and
  248. // not in relation to other elements (.is() is a different story)
  249. filterit( "#posp .firsta", "#posp a:first", 1 );
  250. filterit( "#posp .firsta", "#posp a:last", 1 );
  251. filterit( "#posp .firsta", "#posp a:last-child", 0 );
  252. filterit( "#posp .firsta", "#posp a:even", 1 );
  253. filterit( "#posp .firsta", "#posp a:odd", 0 );
  254. filterit( "#posp .firsta", "#posp a:eq(0)", 1 );
  255. filterit( "#posp .firsta", "#posp a:eq(9)", 0 );
  256. filterit( "#posp .firsta", "#posp em:eq(0)", 0 );
  257. filterit( "#posp .firsta", "#posp em:first", 0 );
  258. filterit( "#posp .firsta", "#posp:first", 0 );
  259. filterit( "#posp .seconda", "#posp a:first", 1 );
  260. filterit( "#posp .seconda", "#posp em:first", 0 );
  261. filterit( "#posp .seconda", "#posp a:last", 1 );
  262. filterit( "#posp .seconda", "#posp a:gt(0)", 0 );
  263. filterit( "#posp .seconda", "#posp a:lt(5)", 1 );
  264. filterit( "#posp .seconda", "#posp a:lt(1)", 1 );
  265. });
  266. test("closest()", function() {
  267. expect( 13 );
  268. var jq;
  269. deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
  270. deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
  271. deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" );
  272. deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" );
  273. // Test .closest() limited by the context
  274. jq = jQuery("#nothiddendivchild");
  275. deepEqual( jq.closest("html", document.body).get(), [], "Context limited." );
  276. deepEqual( jq.closest("body", document.body).get(), [], "Context limited." );
  277. deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." );
  278. //Test that .closest() returns unique'd set
  279. equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" );
  280. // Test on disconnected node
  281. equal( jQuery("<div><p></p></div>").find("p").closest("table").length, 0, "Make sure disconnected closest work." );
  282. // Bug #7369
  283. equal( jQuery("<div foo='bar'></div>").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" );
  284. equal( jQuery("<div>text</div>").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" );
  285. ok( !jQuery(document).closest("#foo").length, "Calling closest on a document fails silently" );
  286. jq = jQuery("<div>text</div>");
  287. deepEqual( jq.contents().closest("*").get(), jq.get(), "Text node input (#13332)" );
  288. });
  289. test("closest() with positional selectors", function() {
  290. expect( 2 );
  291. deepEqual( jQuery("#qunit-fixture").closest("div:first").get(), [], "closest(div:first)" );
  292. deepEqual( jQuery("#qunit-fixture div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
  293. });
  294. test("closest(jQuery)", function() {
  295. expect(8);
  296. var $child = jQuery("#nothiddendivchild"),
  297. $parent = jQuery("#nothiddendiv"),
  298. $sibling = jQuery("#foo"),
  299. $body = jQuery("body");
  300. ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" );
  301. ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" );
  302. ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" );
  303. ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" );
  304. equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" );
  305. equal( $child.closest( $sibling ).length, 0, "Sibling not a parent of child" );
  306. equal( $child.closest( $sibling[0] ).length, 0, "Sibling not a parent of child :: node" );
  307. ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." );
  308. });
  309. test("not(Selector|undefined)", function() {
  310. expect(11);
  311. equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" );
  312. deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
  313. deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
  314. deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
  315. deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
  316. deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')");
  317. var all = jQuery("p").get();
  318. deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect");
  319. deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect");
  320. deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect");
  321. deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect");
  322. deepEqual(
  323. jQuery("#form option").not("option.emptyopt:contains('Nothing'),optgroup *,[value='1']").get(),
  324. q("option1c", "option1d", "option2c", "option2d", "option3c", "option3d", "option3e", "option4d", "option4e", "option5a", "option5b"),
  325. "not('complex selector')"
  326. );
  327. });
  328. test("not(Element)", function() {
  329. expect(1);
  330. var selects = jQuery("#form select");
  331. deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element");
  332. });
  333. test("not(Function)", function() {
  334. expect(1);
  335. deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length; }).get(), q("sndp", "first"), "not(Function)" );
  336. });
  337. test("not(Array)", function() {
  338. expect(2);
  339. equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
  340. equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
  341. });
  342. test("not(jQuery)", function() {
  343. expect( 1 );
  344. deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
  345. });
  346. test("has(Element)", function() {
  347. expect(3);
  348. var obj, detached, multipleParent;
  349. obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]);
  350. deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" );
  351. detached = jQuery("<a><b><i/></b></a>");
  352. deepEqual( detached.has( detached.find("i")[0] ).get(), detached.get(), "...Even when detached" );
  353. multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]);
  354. deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
  355. });
  356. test("has(Selector)", function() {
  357. expect( 5 );
  358. var obj, detached, multipleParent, multipleHas;
  359. obj = jQuery("#qunit-fixture").has("#sndp");
  360. deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" );
  361. detached = jQuery("<a><b><i/></b></a>");
  362. deepEqual( detached.has("i").get(), detached.get(), "...Even when detached" );
  363. multipleParent = jQuery("#qunit-fixture, #header").has("#sndp");
  364. deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" );
  365. multipleParent = jQuery("#select1, #select2, #select3").has("#option1a, #option3a");
  366. deepEqual( multipleParent.get(), q("select1", "select3"), "Multiple contexts are checks correctly" );
  367. multipleHas = jQuery("#qunit-fixture").has("#sndp, #first");
  368. deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
  369. });
  370. test("has(Arrayish)", function() {
  371. expect(4);
  372. var simple, detached, multipleParent, multipleHas;
  373. simple = jQuery("#qunit-fixture").has(jQuery("#sndp"));
  374. deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" );
  375. detached = jQuery("<a><b><i/></b></a>");
  376. deepEqual( detached.has( detached.find("i") ).get(), detached.get(), "...Even when detached" );
  377. multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp"));
  378. deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" );
  379. multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first"));
  380. deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" );
  381. });
  382. test("addBack()", function() {
  383. expect(5);
  384. deepEqual( jQuery("#en").siblings().addBack().get(), q("sndp", "en", "sap"), "Check for siblings and self" );
  385. deepEqual( jQuery("#foo").children().addBack().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" );
  386. deepEqual( jQuery("#sndp, #en").parent().addBack().get(), q("foo","sndp","en"), "Check for parent and self" );
  387. deepEqual( jQuery("#groups").parents("p, div").addBack().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" );
  388. deepEqual( jQuery("#select1 > option").filter(":first-child").addBack(":last-child").get(), q("option1a", "option1d"), "Should contain the last elems plus the *filtered* prior set elements" );
  389. });
  390. test("siblings([String])", function() {
  391. expect(6);
  392. deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
  393. deepEqual( jQuery("#nonnodes").contents().eq(1).siblings().get(), q("nonnodesElement"), "Check for text node siblings" );
  394. deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
  395. var set = q("sndp", "en", "sap");
  396. deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
  397. deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" );
  398. equal( jQuery("<a/>").siblings().length, 0, "Detached elements have no siblings (#11370)" );
  399. });
  400. test("siblings([String]) - jQuery only", function() {
  401. expect(2);
  402. deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
  403. deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
  404. });
  405. test("children([String])", function() {
  406. expect(2);
  407. deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
  408. deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
  409. });
  410. test("children([String]) - jQuery only", function() {
  411. expect(1);
  412. deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
  413. });
  414. test("parent([String])", function() {
  415. expect(6);
  416. var $el;
  417. equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
  418. equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
  419. equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
  420. equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
  421. deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
  422. $el = jQuery("<div>text</div>");
  423. deepEqual( $el.contents().parent().get(), $el.get(), "Check for parent of text node (#13265)" );
  424. });
  425. test("parents([String])", function() {
  426. expect(6);
  427. equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
  428. deepEqual( jQuery("#nonnodes").contents().eq(1).parents().eq(0).get(), q("nonnodes"), "Text node parents check" );
  429. equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
  430. equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" );
  431. deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" );
  432. deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" );
  433. });
  434. test("parentsUntil([String])", function() {
  435. expect(10);
  436. var parents = jQuery("#groups").parents();
  437. deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" );
  438. deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" );
  439. deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.slice(0, -1).get(), "Simple parentsUntil check" );
  440. equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" );
  441. deepEqual( jQuery("#nonnodes").contents().eq(1).parentsUntil("#html").eq(0).get(), q("nonnodes"), "Text node parentsUntil check" );
  442. deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" );
  443. deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" );
  444. deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" );
  445. equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" );
  446. deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" );
  447. });
  448. test("next([String])", function() {
  449. expect(6);
  450. equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
  451. equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).next().attr("id"), "element", "Text node next check" );
  452. equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
  453. equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
  454. equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
  455. equal( jQuery("body").next().length, 0, "Simple next check, no match" );
  456. });
  457. test("prev([String])", function() {
  458. expect(5);
  459. equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
  460. deepEqual( jQuery("#nonnodes").contents().eq(1).prev().get(), q("nonnodesElement"), "Text node prev check" );
  461. equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
  462. equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
  463. equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
  464. });
  465. test("nextAll([String])", function() {
  466. expect(5);
  467. var elems = jQuery("#form").children();
  468. deepEqual( jQuery("#label-for").nextAll().get(), elems.slice(1).get(), "Simple nextAll check" );
  469. equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextAll().attr("id"), "element", "Text node nextAll check" );
  470. deepEqual( jQuery("#label-for").nextAll("input").get(), elems.slice(1).filter("input").get(), "Filtered nextAll check" );
  471. deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multiple-filtered nextAll check" );
  472. deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.slice(1).filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" );
  473. });
  474. test("prevAll([String])", function() {
  475. expect(5);
  476. var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() );
  477. deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" );
  478. deepEqual( jQuery("#nonnodes").contents().eq(1).prevAll().get(), q("nonnodesElement"), "Text node prevAll check" );
  479. deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" );
  480. deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" );
  481. deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" );
  482. });
  483. test("nextUntil([String])", function() {
  484. expect(12);
  485. var elems = jQuery("#form").children().slice( 2, 12 );
  486. deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" );
  487. equal( jQuery("<div>text<a id='element'></a></div>").contents().eq(0).nextUntil().attr("id"), "element", "Text node nextUntil with no selector (nextAll)" );
  488. deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" );
  489. deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" );
  490. equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" );
  491. deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" );
  492. deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" );
  493. deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" );
  494. deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" );
  495. equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" );
  496. deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" );
  497. deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" );
  498. });
  499. test("prevUntil([String])", function() {
  500. expect(11);
  501. var elems = jQuery("#area1").prevAll();
  502. deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" );
  503. deepEqual( jQuery("#nonnodes").contents().eq(1).prevUntil().get(), q("nonnodesElement"), "Text node prevUntil with no selector (prevAll)" );
  504. deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" );
  505. deepEqual( jQuery("#area1").prevUntil("label").get(), elems.slice(0, -1).get(), "Simple prevUntil check" );
  506. equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" );
  507. deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" );
  508. deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.slice(0, -1).not("button").get(), "Filtered prevUntil check" );
  509. deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.slice(0, -1).not("input").get(), "Filtered prevUntil check" );
  510. deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multiple-filtered prevUntil check" );
  511. equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" );
  512. deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.slice(0, -1).get(), "Multi-source, multiple-filtered prevUntil check" );
  513. });
  514. test("contents()", function() {
  515. expect(12);
  516. var ibody, c;
  517. equal( jQuery("#ap").contents().length, 9, "Check element contents" );
  518. ok( jQuery("#iframe").contents()[0], "Check existence of IFrame document" );
  519. ibody = jQuery("#loadediframe").contents()[0].body;
  520. ok( ibody, "Check existence of IFrame body" );
  521. equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
  522. jQuery(ibody).append("<div>init text</div>");
  523. equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
  524. equal( jQuery("div", ibody).last().text(), "init text", "Add text to div in IFrame" );
  525. jQuery("div", ibody).last().text("div text");
  526. equal( jQuery("div", ibody).last().text(), "div text", "Add text to div in IFrame" );
  527. jQuery("div", ibody).last().remove();
  528. equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
  529. equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
  530. jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
  531. jQuery("table", ibody).remove();
  532. equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
  533. // using contents will get comments regular, text, and comment nodes
  534. c = jQuery("#nonnodes").contents().contents();
  535. equal( c.length, 1, "Check node,textnode,comment contents is just one" );
  536. equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
  537. });
  538. test("sort direction", function() {
  539. expect( 12 );
  540. var elems = jQuery("#ap, #select1 > *, #moretests > form"),
  541. methodDirections = {
  542. parent: false,
  543. parents: true,
  544. parentsUntil: true,
  545. next: false,
  546. prev: false,
  547. nextAll: false,
  548. prevAll: true,
  549. nextUntil: false,
  550. prevUntil: true,
  551. siblings: false,
  552. children: false,
  553. contents: false
  554. };
  555. jQuery.each( methodDirections, function( method, reversed ) {
  556. var actual = elems[ method ]().get(),
  557. forward = jQuery.unique( [].concat( actual ) );
  558. deepEqual( actual, reversed ? forward.reverse() : forward, "Correct sort direction for " + method );
  559. });
  560. });
  561. test("add(String|Element|Array|undefined)", function() {
  562. expect( 15 );
  563. var divs, tmp, x, notDefined;
  564. deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
  565. deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
  566. // We no longer support .add(form.elements), unfortunately.
  567. // There is no way, in browsers, to reliably determine the difference
  568. // between form.elements and form - and doing .add(form) and having it
  569. // add the form elements is way to unexpected, so this gets the boot.
  570. // ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" );
  571. // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE
  572. // use jQuery([]).add(form.elements) instead.
  573. //equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" );
  574. divs = jQuery("<div/>").add("#sndp");
  575. ok( divs[0].parentNode, "Sort with the disconnected node last (started with disconnected first)." );
  576. divs = jQuery("#sndp").add("<div/>");
  577. ok( !divs[1].parentNode, "Sort with the disconnected node last." );
  578. tmp = jQuery("<div/>");
  579. x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp));
  580. equal( x[0].id, "x1", "Check on-the-fly element1" );
  581. equal( x[1].id, "x2", "Check on-the-fly element2" );
  582. x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>").appendTo(tmp)[0]).add(jQuery("<p id='x2'>xxx</p>").appendTo(tmp)[0]);
  583. equal( x[0].id, "x1", "Check on-the-fly element1" );
  584. equal( x[1].id, "x2", "Check on-the-fly element2" );
  585. x = jQuery([]).add(jQuery("<p id='x1'>xxx</p>")).add(jQuery("<p id='x2'>xxx</p>"));
  586. equal( x[0].id, "x1", "Check on-the-fly element1" );
  587. equal( x[1].id, "x2", "Check on-the-fly element2" );
  588. x = jQuery([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
  589. equal( x[0].id, "x1", "Check on-the-fly element1" );
  590. equal( x[1].id, "x2", "Check on-the-fly element2" );
  591. equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" );
  592. equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" );
  593. equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" );
  594. });
  595. test("add(String, Context)", function() {
  596. expect(6);
  597. deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " );
  598. deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" );
  599. deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" );
  600. var ctx = document.getElementById("firstp");
  601. deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " );
  602. deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" );
  603. deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" );
  604. });
  605. test("eq('-1') #10616", function() {
  606. expect(3);
  607. var $divs = jQuery( "div" );
  608. equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" );
  609. equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" );
  610. deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" );
  611. });
  612. test("index(no arg) #10977", function() {
  613. expect(2);
  614. var $list, fragment, div;
  615. $list = jQuery("<ul id='indextest'><li class='zero'>THIS ONE</li><li class='one'>a</li><li class='two'>b</li><li class='three'>c</li></ul>");
  616. jQuery("#qunit-fixture").append( $list );
  617. strictEqual ( jQuery( "#indextest li.zero" ).first().index() , 0, "No Argument Index Check" );
  618. $list.remove();
  619. fragment = document.createDocumentFragment();
  620. div = fragment.appendChild( document.createElement("div") );
  621. equal( jQuery( div ).index(), 0, "If jQuery#index called on element whose parent is fragment, it still should work correctly" );
  622. });
  623. test("traversing non-elements with attribute filters (#12523)", function() {
  624. expect(5);
  625. var nonnodes = jQuery("#nonnodes").contents();
  626. equal( nonnodes.filter("[id]").length, 1, ".filter" );
  627. equal( nonnodes.find("[id]").length, 0, ".find" );
  628. strictEqual( nonnodes.is("[id]"), true, ".is" );
  629. deepEqual( nonnodes.closest("[id='nonnodes']").get(), q("nonnodes"), ".closest" );
  630. deepEqual( nonnodes.parents("[id='nonnodes']").get(), q("nonnodes"), ".parents" );
  631. });