MCPcopy Index your code
hub / github.com/jquery/jquery / testText

Function testText

test/unit/manipulation.js:67–99  ·  view source on GitHub ↗
( valueObj, assert )

Source from the content-addressed store, hash-verified

65} );
66
67function 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, "&gt;" ), "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "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
101QUnit.test( "text(String)", function( assert ) {
102 testText( manipulationBareObj, assert );

Callers 1

manipulation.jsFile · 0.85

Calls 1

jQueryFunction · 0.50

Tested by

no test coverage detected