Moved the val() tests from manipulation into attributes.
[jquery.git] / test / unit / manipulation.js
index 4631ead..97f1e5d 100644 (file)
@@ -105,7 +105,7 @@ test("wrapAll(String|Element)", function() {
 
 // TODO: Figure out why each(wrapAll) is not equivalent to wrapAll
 // test("wrapAll(Function)", function() {
-//     testWrapAll(functionReturningObj);
+//     testWrapAll(functionReturningObj);
 // })
 
 var testWrapInner = function(val) {
@@ -130,7 +130,7 @@ test("wrapInner(String|Element)", function() {
 
 // TODO: wrapInner uses wrapAll -- get wrapAll working with Function
 // test("wrapInner(Function)", function() {
-//     testWrapInner(functionReturningObj)
+//     testWrapInner(functionReturningObj)
 // })
 
 var testUnwrap = function() {
@@ -251,7 +251,7 @@ var testAppend = function(valueObj) {
 }
 
 test("append(String|Element|Array<Element>|jQuery)", function() {
-  testAppend(bareObj);
+       testAppend(bareObj);
 });
 
 test("append(Function)", function() {
@@ -549,7 +549,7 @@ test("replaceAll(String|Element|Array<Element>|jQuery)", function() {
 });
 
 test("clone()", function() {
-       expect(28);
+       expect(30);
        equals( 'This is a normal link: Yahoo', jQuery('#en').text(), 'Assert text for #en' );
        var clone = jQuery('#yahoo').clone();
        equals( 'Try them out:Yahoo', jQuery('#first').append(clone).text(), 'Check for clone' );
@@ -594,6 +594,11 @@ test("clone()", function() {
        div = div.clone(true);
        equals( div.length, 1, "One element cloned" );
        equals( div[0].nodeName.toUpperCase(), "DIV", "DIV element cloned" );
+
+       div = jQuery("<div/>").data({ a: true, b: true });
+       div = div.clone(true);
+       equals( div.data("a"), true, "Data cloned." );
+       equals( div.data("b"), true, "Data cloned." );
 });
 
 if (!isLocal) {
@@ -613,65 +618,6 @@ test("clone() on XML nodes", function() {
 });
 }
 
-test("val()", function() {
-       expect(9);
-
-       document.getElementById('text1').value = "bla";
-       equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
-
-       reset();
-
-       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' );
-
-       same( 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' );
-
-});
-
-var testVal = function(valueObj) {
-       expect(6);
-
-       jQuery("#text1").val(valueObj( 'test' ));
-       equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
-
-       jQuery("#text1").val(valueObj( 67 ));
-       equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
-
-       jQuery("#select1").val(valueObj( "3" ));
-       equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
-
-       jQuery("#select1").val(valueObj( 2 ));
-       equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
-
-  jQuery("#select1").append("<option value='4'>four</option>");
-  jQuery("#select1").val(valueObj( 4 ));
-  equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
-
-       // using contents will get comments regular, text, and comment nodes
-       var j = jQuery("#nonnodes").contents();
-       j.val(valueObj( "asdf" ));
-       equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
-       j.removeAttr("value");
-}
-
-test("val(String/Number)", function() {
-       testVal(bareObj);
-});
-
-test("val(Function)", function() {
-       testVal(functionReturningObj);
-})
-
 var testHtml = function(valueObj) {
        expect(22);
 
@@ -734,15 +680,16 @@ test("html(String)", function() {
 
 test("html(Function)", function() {
        testHtml(functionReturningObj);
-})
+});
 
 var testText = function(valueObj) {
        expect(4);
-       equals( jQuery("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
+       var val = valueObj("<div><b>Hello</b> cruel world!</div>");
+       equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, "&gt;"), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
 
        // using contents will get comments regular, text, and comment nodes
        var j = jQuery("#nonnodes").contents();
-       j.text("hi!");
+       j.text(valueObj("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()" );