| 65 | } ); |
| 66 | |
| 67 | function testText( valueObj, assert ) { |
| 68 | |
| 69 | assert.expect( 6 ); |
| 70 | |
| 71 | var val, j, expected, $multipleElements, $parentDiv, $childDiv; |
| 72 | |
| 73 | val = valueObj( "<div><b>Hello</b> cruel world!</div>" ); |
| 74 | assert.equal( jQuery( "#foo" ).text( val )[ 0 ].innerHTML.replace( />/g, ">" ), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" ); |
| 75 | |
| 76 | // using contents will get comments regular, text, and comment nodes |
| 77 | j = jQuery( "#nonnodes" ).contents(); |
| 78 | j.text( valueObj( "hi!" ) ); |
| 79 | assert.equal( jQuery( j[ 0 ] ).text(), "hi!", "Check node,textnode,comment with text()" ); |
| 80 | assert.equal( j[ 1 ].nodeValue, " there ", "Check node,textnode,comment with text()" ); |
| 81 | |
| 82 | assert.equal( j[ 2 ].nodeType, 8, "Check node,textnode,comment with text()" ); |
| 83 | |
| 84 | // Update multiple elements trac-11809 |
| 85 | expected = "New"; |
| 86 | |
| 87 | $multipleElements = jQuery( "<div>Hello</div>" ).add( "<div>World</div>" ); |
| 88 | $multipleElements.text( expected ); |
| 89 | |
| 90 | assert.equal( $multipleElements.eq( 0 ).text(), expected, "text() updates multiple elements (trac-11809)" ); |
| 91 | assert.equal( $multipleElements.eq( 1 ).text(), expected, "text() updates multiple elements (trac-11809)" ); |
| 92 | |
| 93 | // Prevent memory leaks trac-11809 |
| 94 | $childDiv = jQuery( "<div></div>" ); |
| 95 | $childDiv.data( "leak", true ); |
| 96 | $parentDiv = jQuery( "<div></div>" ); |
| 97 | $parentDiv.append( $childDiv ); |
| 98 | $parentDiv.text( "Dry off" ); |
| 99 | } |
| 100 | |
| 101 | QUnit.test( "text(String)", function( assert ) { |
| 102 | testText( manipulationBareObj, assert ); |