+test("html(Function) with incoming value", function() {
+ expect(20);
+
+ var div = jQuery("#main > div"), old = div.map(function(){ return jQuery(this).html() });
+
+ div.html(function(i, val) {
+ equals( val, old[i], "Make sure the incoming value is correct." );
+ return "<b>test</b>";
+ });
+
+ var pass = true;
+ div.each(function(){
+ if ( this.childNodes.length !== 1 ) {
+ pass = false;
+ }
+ })
+ ok( pass, "Set HTML" );
+
+ QUnit.reset();
+ // using contents will get comments regular, text, and comment nodes
+ var j = jQuery("#nonnodes").contents();
+ old = j.map(function(){ return jQuery(this).html(); });
+
+ j.html(function(i, val) {
+ equals( val, old[i], "Make sure the incoming value is correct." );
+ return "<b>bold</b>";
+ });
+
+ // Handle the case where no comment is in the document
+ if ( j.length === 2 ) {
+ equals( null, null, "Make sure the incoming value is correct." );
+ }
+
+ j.find('b').removeData();
+ equals( j.html().replace(/ xmlns="[^"]+"/g, "").toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
+
+ var $div = jQuery('<div />');
+
+ equals( $div.html(function(i, val) {
+ equals( val, "", "Make sure the incoming value is correct." );
+ return 5;
+ }).html(), '5', 'Setting a number as html' );
+
+ equals( $div.html(function(i, val) {
+ equals( val, "5", "Make sure the incoming value is correct." );
+ return 0;
+ }).html(), '0', 'Setting a zero as html' );
+
+ var $div2 = jQuery('<div/>'), insert = "<div>hello1</div>";
+ equals( $div2.html(function(i, val) {
+ equals( val, "", "Make sure the incoming value is correct." );
+ return insert;
+ }).html().replace(/>/g, ">"), insert, "Verify escaped insertion." );
+
+ equals( $div2.html(function(i, val) {
+ equals( val.replace(/>/g, ">"), insert, "Make sure the incoming value is correct." );
+ return "x" + insert;
+ }).html().replace(/>/g, ">"), "x" + insert, "Verify escaped insertion." );
+
+ equals( $div2.html(function(i, val) {
+ equals( val.replace(/>/g, ">"), "x" + insert, "Make sure the incoming value is correct." );
+ return " " + insert;
+ }).html().replace(/>/g, ">"), " " + insert, "Verify escaped insertion." );
+});
+