0
@@ -12,6 +12,42 @@ test("text()", function() {
0
equals( jQuery(document.createTextNode("foo")).text(), "foo", "Text node was retreived from .text()." );
0
+var testText = function(valueObj) {
0
+ var val = valueObj("<div><b>Hello</b> cruel world!</div>");
0
+ equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
0
+ // using contents will get comments regular, text, and comment nodes
0
+ var j = jQuery("#nonnodes").contents();
0
+ j.text(valueObj("hi!"));
0
+ equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
0
+ equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
0
+ equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
0
+test("text(String)", function() {
0
+test("text(Function)", function() {
0
+ testText(functionReturningObj);
0
+test("text(Function) with incoming value", function() {
0
+ var old = "This link has class=\"blog\": Simon Willison's Weblog";
0
+ jQuery('#sap').text(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
0
var testWrap = function(val) {
0
var defaultText = 'Try them out:'
0
@@ -133,7 +169,7 @@ test("wrapInner(String|Element)", function() {
0
// testWrapInner(functionReturningObj)
0
-
var testUnwrap = function() {
0
+
test("unwrap()", function() {
0
jQuery("body").append(' <div id="unwrap" style="display: none;"> <div id="unwrap1"> <span class="unwrap">a</span> <span class="unwrap">b</span> </div> <div id="unwrap2"> <span class="unwrap">c</span> <span class="unwrap">d</span> </div> <div id="unwrap3"> <b><span class="unwrap unwrap3">e</span></b> <b><span class="unwrap unwrap3">f</span></b> </div> </div>');
0
@@ -158,10 +194,6 @@ var testUnwrap = function() {
0
same( jQuery('body > span.unwrap').get(), abcdef, 'body contains 6 .unwrap child spans' );
0
jQuery('body > span.unwrap').remove();
0
-test("unwrap()", function() {
0
var testAppend = function(valueObj) {
0
@@ -256,7 +288,68 @@ test("append(String|Element|Array<Element>|jQuery)", function() {
0
test("append(Function)", function() {
0
testAppend(functionReturningObj);
0
+test("append(Function) with incoming value", function() {
0
+ var defaultText = 'Try them out:', old = jQuery("#first").html();
0
+ var result = jQuery('#first').append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ equals( result.text(), defaultText + 'buga', 'Check if text appending works' );
0
+ var select = jQuery('#select3');
0
+ equals( select.append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return '<option value="appendTest">Append Test</option>';
0
+ }).find('option:last-child').attr('value'), 'appendTest', 'Appending html options to select element');
0
+ var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
0
+ old = jQuery("#sap").html();
0
+ jQuery('#sap').append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return document.getElementById('first');
0
+ equals( expected, jQuery('#sap').text(), "Check for appending of element" );
0
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
0
+ old = jQuery("#sap").html();
0
+ jQuery('#sap').append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return [document.getElementById('first'), document.getElementById('yahoo')];
0
+ equals( expected, jQuery('#sap').text(), "Check for appending of array of elements" );
0
+ expected = "This link has class=\"blog\": Simon Willison's WeblogYahooTry them out:";
0
+ old = jQuery("#sap").html();
0
+ jQuery('#sap').append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return jQuery("#first, #yahoo");
0
+ equals( expected, jQuery('#sap').text(), "Check for appending of jQuery object" );
0
+ old = jQuery("#sap").html();
0
+ jQuery("#sap").append(function(i, val){
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ ok( jQuery("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
0
test("appendTo(String|Element|Array<Element>|jQuery)", function() {
0
@@ -330,7 +423,7 @@ var testPrepend = function(val) {
0
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
0
jQuery('#sap').prepend(val( jQuery("#first, #yahoo") ));
0
equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
0
test("prepend(String|Element|Array<Element>|jQuery)", function() {
0
@@ -338,7 +431,58 @@ test("prepend(String|Element|Array<Element>|jQuery)", function() {
0
test("prepend(Function)", function() {
0
testPrepend(functionReturningObj);
0
+test("prepend(Function) with incoming value", function() {
0
+ var defaultText = 'Try them out:', old = jQuery('#first').html();
0
+ var result = jQuery('#first').prepend(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ equals( result.text(), 'buga' + defaultText, 'Check if text prepending works' );
0
+ old = jQuery("#select3").html();
0
+ equals( jQuery('#select3').prepend(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return '<option value="prependTest">Prepend Test</option>';
0
+ }).find('option:first-child').attr('value'), 'prependTest', 'Prepending html options to select element');
0
+ var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
0
+ old = jQuery('#sap').html();
0
+ jQuery('#sap').prepend(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return document.getElementById('first');
0
+ equals( expected, jQuery('#sap').text(), "Check for prepending of element" );
0
+ expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
0
+ old = jQuery('#sap').html();
0
+ jQuery('#sap').prepend(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return [document.getElementById('first'), document.getElementById('yahoo')];
0
+ equals( expected, jQuery('#sap').text(), "Check for prepending of array of elements" );
0
+ expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
0
+ old = jQuery('#sap').html();
0
+ jQuery('#sap').prepend(function(i, val) {
0
+ equals( val, old, "Make sure the incoming value is correct." );
0
+ return jQuery("#first, #yahoo");
0
+ equals( expected, jQuery('#sap').text(), "Check for prepending of jQuery object" );
0
test("prependTo(String|Element|Array<Element>|jQuery)", function() {
0
@@ -618,92 +762,6 @@ test("clone() on XML nodes", function() {
0
-test("val()", function() {
0
- document.getElementById('text1').value = "bla";
0
- equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
0
- equals( jQuery("#text1").val(), "Test", "Check for value of input element" );
0
- // ticket #1714 this caused a JS error in IE
0
- equals( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
0
- ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
0
- equals( jQuery('#select2').val(), '3', 'Call val() on a single="single" select' );
0
- same( jQuery('#select3').val(), ['1', '2'], 'Call val() on a multiple="multiple" select' );
0
- equals( jQuery('#option3c').val(), '2', 'Call val() on a option element with value' );
0
- equals( jQuery('#option3a').val(), '', 'Call val() on a option element with empty value' );
0
- equals( jQuery('#option3e').val(), 'no value', 'Call val() on a option element with no value attribute' );
0
- equals( jQuery('#option3a').val(), '', 'Call val() on a option element with no value attribute' );
0
- jQuery('#select3').val("");
0
- same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' );
0
- var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form")
0
- .add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") )
0
- .add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") )
0
- .add( jQuery("<input type='checkbox' name='test'/>").appendTo("#form") );
0
- same( checks.serialize(), "", "Get unchecked values." );
0
- equals( checks.eq(3).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
0
- same( checks.serialize(), "test=2", "Get a single checked value." );
0
- checks.val([ "1", "" ]);
0
- same( checks.serialize(), "test=1&test=", "Get multiple checked values." );
0
- checks.val([ "", "2" ]);
0
- same( checks.serialize(), "test=2&test=", "Get multiple checked values." );
0
- checks.val([ "1", "on" ]);
0
- same( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
0
-var testVal = function(valueObj) {
0
- jQuery("#text1").val(valueObj( 'test' ));
0
- equals( document.getElementById('text1').value, "test", "Check for modified (via val(String)) value of input element" );
0
- jQuery("#text1").val(valueObj( 67 ));
0
- equals( document.getElementById('text1').value, "67", "Check for modified (via val(Number)) value of input element" );
0
- jQuery("#select1").val(valueObj( "3" ));
0
- equals( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
0
- jQuery("#select1").val(valueObj( 2 ));
0
- equals( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
0
- jQuery("#select1").append("<option value='4'>four</option>");
0
- jQuery("#select1").val(valueObj( 4 ));
0
- equals( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
0
- // using contents will get comments regular, text, and comment nodes
0
- var j = jQuery("#nonnodes").contents();
0
- j.val(valueObj( "asdf" ));
0
- equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
0
- j.removeAttr("value");
0
-test("val(String/Number)", function() {
0
-test("val(Function)", function() {
0
- testVal(functionReturningObj);
0
var testHtml = function(valueObj) {
0
@@ -768,27 +826,66 @@ test("html(Function)", function() {
0
testHtml(functionReturningObj);
0
-var testText = function(valueObj) {
0
- var val = valueObj("<div><b>Hello</b> cruel world!</div>");
0
- equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
0
+test("html(Function) with incoming value", function() {
0
+ var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
0
+ div.html(function(i, val) {
0
+ equals( val, old[i], "Make sure the incoming value is correct." );
0
+ if ( this.childNodes.length !== 1 ) {
0
+ ok( pass, "Set HTML" );
0
// using contents will get comments regular, text, and comment nodes
0
var j = jQuery("#nonnodes").contents();
0
- j.text(valueObj("hi!"));
0
- equals( jQuery(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
0
- equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
0
- equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
0
+ old = j.map(function(){ return jQuery(this).html(); });
0
+ j.html(function(i, val) {
0
+ equals( val, old[i], "Make sure the incoming value is correct." );
0
+ j.find('b').removeData();
0
+ equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
0
+ var $div = jQuery('<div />');
0
+ equals( $div.html(function(i, val) {
0
+ equals( val, "", "Make sure the incoming value is correct." );
0
+ }).html(), '5', 'Setting a number as html' );
0
+ equals( $div.html(function(i, val) {
0
+ equals( val, "5", "Make sure the incoming value is correct." );
0
+ }).html(), '0', 'Setting a zero as html' );
0
-test("text(String)", function() {
0
+ var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
0
+ equals( $div2.html(function(i, val) {
0
+ equals( val, "", "Make sure the incoming value is correct." );
0
+ }).html(), insert, "Verify escaped insertion." );
0
+ equals( $div2.html(function(i, val) {
0
+ equals( val, insert, "Make sure the incoming value is correct." );
0
+ }).html(), "x" + insert, "Verify escaped insertion." );
0
+ equals( $div2.html(function(i, val) {
0
+ equals( val, "x" + insert, "Make sure the incoming value is correct." );
0
+ }).html(), " " + insert, "Verify escaped insertion." );
0
-test("text(Function)", function() {
0
- testText(functionReturningObj);
0
var testRemove = function(method) {