- 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");
-});
-
-test("html(String)", function() {
- expect(17);
-
- jQuery.scriptorder = 0;
-
- 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().replace(/ xmlns="[^"]+"/g, "").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' );
-
- reset();
-
- jQuery("#main").html('<script type="something/else">ok( false, "Non-script evaluated." );</script><script type="text/javascript">ok( true, "text/javascript is evaluated." );</script><script>ok( true, "No type is evaluated." );</script><div><script type="text/javascript">ok( true, "Inner text/javascript is evaluated." );</script><script>ok( true, "Inner No type is evaluated." );</script><script type="something/else">ok( false, "Non-script evaluated." );</script></div>');
-
- 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(jQuery.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(jQuery.scriptorder++, 1, 'Script (nested) is executed in order');equals(jQuery('#scriptorder').length, 1,'Execute after html')<\/script></span><script>equals(jQuery.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(6);
- 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)" );
-
- isSet( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" );
- isSet( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" );
-});
-
-test("not()", function() {
- expect(11);
- 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");
-
- isSet( jQuery('#ap *').not('code'), q("google", "groups", "anchor1", "mark"), "not('tag selector')" );
- isSet( jQuery('#ap *').not('code, #mark'), q("google", "groups", "anchor1"), "not('tag, ID selector')" );
- isSet( jQuery('#ap *').not('#mark, code'), q("google", "groups", "anchor1"), "not('ID, tag selector')");
-});
-
-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("main", "ap", "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", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" );
- var set = q("en", "sap", "sndp");
- 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("main", "ap"), "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("#main 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 old = jQuery("#show-tests table").show().css("display") !== "table";
-
- var test = {
- "div" : "block",
- "p" : "block",
- "a" : "inline",
- "code" : "inline",
- "pre" : "block",
- "span" : "inline",
- "table" : old ? "block" : "table",
- "thead" : old ? "block" : "table-header-group",
- "tbody" : old ? "block" : "table-row-group",
- "tr" : old ? "block" : "table-row",
- "th" : old ? "block" : "table-cell",
- "td" : old ? "block" : "table-cell",
- "ul" : "block",
- "li" : old ? "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(5);
-
- 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();
-
- // Make sure that a null value doesn't cause problems
- $divs.eq(0).addClass("test").removeClass(null);
- ok( $divs.eq(0).is('.test'), "Null value passed to removeClass" );
-
- $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);
- 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);
- ok( !e.is(".test"), "Assert class not present" );
- e.toggleClass("test", true);
- ok( e.is(".test"), "Assert class present" );
- e.toggleClass("test", false);
- ok( !e.is(".test"), "Assert class not present" );
-});
-
-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.replace(/>/g, ">"), "<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()" );
-});
-
-test("jQuery.each(Object,Function)", function() {
- expect(12);
- jQuery.each( [0,1,2], function(i, n){
- equals( i, n, "Check array iteration" );
- });
-
- jQuery.each( [5,6,7], function(i, n){
- equals( i, n - 5, "Check array iteration" );
- });
-
- jQuery.each( { name: "name", lang: "lang" }, function(i, n){
- equals( i, n, "Check object iteration" );
- });
-
- var total = 0;
- jQuery.each([1,2,3], function(i,v){ total += v; });
- equals( total, 6, "Looping over an array" );
- total = 0;
- jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; });
- equals( total, 3, "Looping over an array, with break" );
- total = 0;
- jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; });
- equals( total, 6, "Looping over an object" );
- total = 0;
- jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; });
- equals( total, 3, "Looping over an object, with break" );
-});
-
-test("jQuery.className", function() {
- expect(6);
- var x = jQuery("<p>Hi</p>")[0];
- var c = jQuery.className;
- c.add(x, "hi");
- equals( x.className, "hi", "Check single added class" );
- c.add(x, "foo bar");
- equals( x.className, "hi foo bar", "Check more added classes" );
- c.remove(x);
- equals( x.className, "", "Remove all classes" );
- c.add(x, "hi foo bar");
- c.remove(x, "foo");
- equals( x.className, "hi bar", "Check removal of one class" );
- ok( c.has(x, "hi"), "Check has1" );
- ok( c.has(x, "bar"), "Check has2" );
-});
-
-test("remove()", function() {
- expect(7);
- jQuery("#ap").children().remove();
- ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
- equals( jQuery("#ap").children().length, 0, "Check remove" );
-
- reset();
- jQuery("#ap").children().remove("a");
- ok( jQuery("#ap").text().length > 10, "Check text is not removed" );
- equals( jQuery("#ap").children().length, 1, "Check filtered remove" );
-
- jQuery("#ap").children().remove("a, code");
- equals( jQuery("#ap").children().length, 0, "Check multi-filtered remove" );
-
- // using contents will get comments regular, text, and comment nodes
- equals( jQuery("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
- jQuery("#nonnodes").contents().remove();
- equals( jQuery("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
-});
-
-test("empty()", function() {
- expect(3);
- equals( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
- equals( jQuery("#ap").children().length, 4, "Check elements are not removed" );
-
- // using contents will get comments regular, text, and comment nodes
- var j = jQuery("#nonnodes").contents();
- j.empty();
- equals( j.html(), "", "Check node,textnode,comment empty works" );
-});
-
-test("slice()", function() {
- expect(6);
-
- var $links = jQuery("#ap a");
-
- isSet( $links.slice(1,2), q("groups"), "slice(1,2)" );
- isSet( $links.slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
- isSet( $links.slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
- isSet( $links.slice(-1), q("mark"), "slice(-1)" );
-
- isSet( $links.eq(1), q("groups"), "eq(1)" );
-
- isSet( $links.eq('2'), q("anchor1"), "eq('2')" );
-});
-
-test("map()", function() {
- expect(2);//expect(6);
-
- isSet(
- jQuery("#ap").map(function(){
- return jQuery(this).find("a").get();
- }),
- q("google", "groups", "anchor1", "mark"),
- "Array Map"
- );
-
- isSet(
- jQuery("#ap > a").map(function(){
- return this.parentNode;
- }),
- q("ap","ap","ap"),
- "Single Map"
- );
-
- return;//these haven't been accepted yet
-
- //for #2616
- var keys = jQuery.map( {a:1,b:2}, function( v, k ){
- return k;
- }, [ ] );
-
- equals( keys.join(""), "ab", "Map the keys from a hash to an array" );
-
- var values = jQuery.map( {a:1,b:2}, function( v, k ){
- return v;
- }, [ ] );
-
- equals( values.join(""), "12", "Map the values from a hash to an array" );
-
- var scripts = document.getElementsByTagName("script");
- var mapped = jQuery.map( scripts, function( v, k ){
- return v;
- }, {length:0} );
-
- equals( mapped.length, scripts.length, "Map an array(-like) to a hash" );
-
- var flat = jQuery.map( Array(4), function( v, k ){
- return k % 2 ? k : [k,k,k];//try mixing array and regular returns
- });
-
- equals( flat.join(""), "00012223", "try the new flatten technique(#2616)" );
-});
-
-test("contents()", function() {
- expect(12);
- equals( jQuery("#ap").contents().length, 9, "Check element contents" );
- ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" );
- var ibody = jQuery("#loadediframe").contents()[0].body;
- ok( ibody, "Check existance of IFrame body" );
-
- equals( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
-
- jQuery(ibody).append("<div>init text</div>");
- equals( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
-
- equals( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
-
- jQuery("div:last", ibody).text("div text");
- equals( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
-
- jQuery("div:last", ibody).remove();
- equals( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
-
- equals( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
-
- jQuery("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
- jQuery("table", ibody).remove();
- equals( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
-
- // using contents will get comments regular, text, and comment nodes
- var c = jQuery("#nonnodes").contents().contents();
- equals( c.length, 1, "Check node,textnode,comment contents is just one" );
- equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
-});
-
-test("jQuery.makeArray", function(){
- expect(15);
-
- equals( jQuery.makeArray(jQuery('html>*'))[0].nodeName.toUpperCase(), "HEAD", "Pass makeArray a jQuery object" );
-
- equals( jQuery.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" );
-
- equals( (function(){ return jQuery.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" );
-
- equals( jQuery.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" );
-
- equals( jQuery.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" );
-
- equals( jQuery.makeArray( 0 )[0], 0 , "Pass makeArray a number" );
-
- equals( jQuery.makeArray( "foo" )[0], "foo", "Pass makeArray a string" );
-
- equals( jQuery.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" );
-
- equals( jQuery.makeArray( document.createElement("div") )[0].nodeName.toUpperCase(), "DIV", "Pass makeArray a single node" );
-
- equals( jQuery.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" );
-
- ok( !!jQuery.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "Pass makeArray a childNodes array" );
-
- // function, is tricky as it has length
- equals( jQuery.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" );
-
- //window, also has length
- equals( jQuery.makeArray(window)[0], window, "Pass makeArray the window" );
-
- equals( jQuery.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" );
-
- ok( jQuery.makeArray(document.getElementById('form')).length >= 13, "Pass makeArray a form (treat as elements)" );