+var testText = function(valueObj) {
+ expect(4);
+ var val = valueObj("<div><b>Hello</b> cruel world!</div>");
+ equals( jQuery("#foo").text(val)[0].innerHTML.replace(/>/g, ">"), "<div><b>Hello</b> cruel world!</div>", "Check escaped text" );
+
+ // using contents will get comments regular, text, and comment nodes
+ var j = jQuery("#nonnodes").contents();
+ 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()" );
+}
+
+test("text(String)", function() {
+ testText(bareObj)
+});
+
+test("text(Function)", function() {
+ testText(functionReturningObj);
+});
+
+test("text(Function) with incoming value", function() {
+ expect(2);
+
+ var old = "This link has class=\"blog\": Simon Willison's Weblog";
+
+ jQuery('#sap').text(function(i, val) {
+ equals( val, old, "Make sure the incoming value is correct." );
+ return "foobar";
+ });
+
+ equals( jQuery("#sap").text(), "foobar", 'Check for merged text of more then one element.' );
+
+ reset();
+});
+