- isObj( settings, merged2, "Check if extended: settings must be extended" );
- isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
- isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
- isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
-});
-
-test("val()", function() {
- expect(8);
-
- equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
- // ticket #1714 this caused a JS error in IE
- equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
- ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
-
- equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
-
- isSet( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
-
- equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
-
- equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
-
- equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
-
-});
-
-test("val(String/Number)", function() {
- expect(6);
- document.getElementById('text1').value = "bla";
- equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
-
- jQuery("#text1").val('test');
- equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
-
- jQuery("#text1").val(67);
- equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
-
- jQuery("#select1").val("3");
- equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
-
- jQuery("#select1").val(2);
- equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.val("asdf");
- equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
- j.removeAttr("value");
-});
-
-var scriptorder = 0;
-
-test("html(String)", function() {
- expect(13);
- var div = jQuery("#main > div");
- div.html("<b>test</b>");
- var pass = true;
- for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).childNodes.length != 1 ) pass = false;
- }
- ok( pass, "Set HTML" );
-
- reset();
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.html("<b>bold</b>");
-
- // this is needed, or the expando added by jQuery unique will yield a different html
- j.find('b').removeData();
- equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
-
- jQuery("#main").html("<select/>");
- jQuery("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
- equals( jQuery("#main select").val(), "O2", "Selected option correct" );
-
- var $div = jQuery('<div />');
- equals( $div.html( 5 ).html(), '5', 'Setting a number as html' );
- equals( $div.html( 0 ).html(), '0', 'Setting a zero as html' );
-
- stop();
-
- jQuery("#main").html('<script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
-
- jQuery("#main").html('foo <form><script type="text/javascript">ok( true, "jQuery().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
-
- // it was decided that waiting to execute ALL scripts makes sense since nested ones have to wait anyway so this test case is changed, see #1959
- jQuery("#main").html("<script>equals(scriptorder++, 0, 'Script is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html (even though appears before)')<\/script><span id='scriptorder'><script>equals(scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(scriptorder++, 2, 'Script (unnested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script>");
-
- setTimeout( start, 100 );
-});
-
-test("filter()", function() {
- expect(6);
- isSet( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
- isSet( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
- isSet( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
- isSet( jQuery("p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
- equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
-});
-
-test("closest()", function() {
- expect(4);
- isSet( jQuery("body").closest("body").get(), q("body"), "closest(body)" );
- isSet( jQuery("body").closest("html").get(), q("html"), "closest(html)" );
- isSet( jQuery("body").closest("div").get(), [], "closest(div)" );
- isSet( jQuery("#main").closest("span,#html").get(), q("html"), "closest(span,#html)" );
-});
-
-test("not()", function() {
- expect(8);
- equals( jQuery("#main > p#ap > a").not("#google").length, 2, "not('selector')" );
- equals( jQuery("#main > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" );
- isSet( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" );
- isSet( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
- isSet( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
- equals( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" );
- isSet( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e" ), "not('complex selector')");
-
- var selects = jQuery("#form select");
- isSet( selects.not( selects[1] ), q("select1", "select3"), "filter out DOM element");
-});
-
-test("andSelf()", function() {
- expect(4);
- isSet( jQuery("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
- isSet( jQuery("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
- isSet( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" );
- isSet( jQuery("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
-});
-
-test("siblings([String])", function() {
- expect(5);
- isSet( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
- isSet( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" );
- isSet( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
- isSet( jQuery("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
- var set = document.querySelectorAll ? q("en", "sap", "sndp") : q("sndp", "sap", "en");
- isSet( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" );
-});
-
-test("children([String])", function() {
- expect(3);
- isSet( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
- isSet( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
- isSet( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
-});
-
-test("parent([String])", function() {
- expect(5);
- equals( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" );
- equals( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" );
- equals( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" );
- equals( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" );
- isSet( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
-});
-
-test("parents([String])", function() {
- expect(5);
- equals( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" );
- equals( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" );
- equals( jQuery("#groups").parents("div")[0].id, "main", "Filtered parents check2" );
- isSet( jQuery("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
- isSet( jQuery("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
-});
-
-test("next([String])", function() {
- expect(4);
- equals( jQuery("#ap").next()[0].id, "foo", "Simple next check" );
- equals( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" );
- equals( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" );
- equals( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" );
-});
-
-test("prev([String])", function() {
- expect(4);
- equals( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" );
- equals( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" );
- equals( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" );
- equals( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" );
-});
-
-test("show()", function() {
- expect(15);
- var pass = true, div = jQuery("div");
- div.show().each(function(){
- if ( this.style.display == "none" ) pass = false;
- });
- ok( pass, "Show" );
-
- jQuery("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
- var test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : jQuery.browser.msie ? "block" : "table",
- "thead" : jQuery.browser.msie ? "block" : "table-header-group",
- "tbody" : jQuery.browser.msie ? "block" : "table-row-group",
- "tr" : jQuery.browser.msie ? "block" : "table-row",
- "th" : jQuery.browser.msie ? "block" : "table-cell",
- "td" : jQuery.browser.msie ? "block" : "table-cell",
- "ul" : "block",
- "li" : jQuery.browser.msie ? "block" : "list-item"
- };
-
- jQuery.each(test, function(selector, expected) {
- var elem = jQuery(selector, "#show-tests").show();
- equals( elem.css("display"), expected, "Show using correct display type for " + selector );
- });
-});
-
-test("addClass(String)", function() {
- expect(2);
- var div = jQuery("div");
- div.addClass("test");
- var pass = true;
- for ( var i = 0; i < div.size(); i++ ) {
- if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
- }
- ok( pass, "Add Class" );
-
- // using contents will get regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.addClass("asdf");
- ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
-});
-
-test("removeClass(String) - simple", function() {
- expect(4);
-
- var $divs = jQuery('div');
-
- $divs.addClass("test").removeClass("test");
-
- ok( !$divs.is('.test'), "Remove Class" );
-
- reset();
-
- $divs.addClass("test").addClass("foo").addClass("bar");
- $divs.removeClass("test").removeClass("bar").removeClass("foo");
-
- ok( !$divs.is('.test,.bar,.foo'), "Remove multiple classes" );
-
- reset();
-
- $divs.eq(0).addClass("test").removeClass("");
- ok( $divs.eq(0).is('.test'), "Empty string passed to removeClass" );
-
- // using contents will get regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.removeClass("asdf");
- ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
-});
-
-test("toggleClass(String)", function() {
- expect(6);\r
- var e = jQuery("#firstp");
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass("test");
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass("test");
- ok( !e.is(".test"), "Assert class not present" );
-
- e.toggleClass("test", false);\r
- ok( !e.is(".test"), "Assert class not present" );\r
- e.toggleClass("test", true);\r
- ok( e.is(".test"), "Assert class present" );\r
- e.toggleClass("test", false);\r
- ok( !e.is(".test"), "Assert class not present" );\r
-});
-
-test("removeAttr(String", function() {
- expect(1);
- equals( jQuery('#mark').removeAttr("class")[0].className, "", "remove class" );
-});
-
-test("text(String)", function() {
- expect(4);
- equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML, "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.text("hi!");
- equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
- equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
- equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );