aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authortimmywil <timmywillisn@gmail.com>2012-06-21 15:28:57 -0400
committertimmywil <timmywillisn@gmail.com>2012-06-21 15:39:04 -0400
commite2497c682f26b7916d76cb2896c6fe621b376d82 (patch)
treebb07d0b4f1b1dd07d34934648a6498e09c80c786 /test/unit
parent7ff3da186cf9bb5ea23f5a0b9543302ef0f861f7 (diff)
downloadjquery-e2497c682f26b7916d76cb2896c6fe621b376d82.tar.gz
jquery-e2497c682f26b7916d76cb2896c6fe621b376d82.zip
Add parseHTML for explicitly parsing strings into html. Fixes #11617.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/core.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/unit/core.js b/test/unit/core.js
index 71737a87e..f2f5f41c4 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -1120,6 +1120,35 @@ test("jQuery.proxy", function(){
jQuery.proxy( test4, "meth" )( "boom" );
});
+test("jQuery.parseHTML", function() {
+ expect( 11 );
+
+ equal( jQuery.parseHTML(), null, "Nothing in, null out." );
+ equal( jQuery.parseHTML( null ), null, "Nothing in, null out." );
+ equal( jQuery.parseHTML( "" ), null, "Nothing in, null out." );
+ raises(function() {
+ jQuery.parseHTML( "<div>", document.getElementById("form") );
+ }, "Passing an element as the context raises an exception (context should be a document)");
+
+ var elems = jQuery.parseHTML( jQuery("body").html() );
+ ok( elems.length > 10, "Parse a large html string" );
+ equal( jQuery.type( elems ), "array", "parseHTML returns an array rather than a nodelist" );
+
+ var script = "<script>undefined()</script>";
+ equal( jQuery.parseHTML( script ).length, 0, "Passing a script is not allowed by default" );
+ raises(function() {
+ jQuery(jQuery.parseHTML( script, true )).appendTo("#qunit-fixture");
+ }, "Passing a script is allowed if allowScripts is true");
+
+ var html = script + "<div></div>";
+ equal( jQuery.parseHTML( html )[0].nodeName.toLowerCase(), "div", "Ignore scripts by default" );
+ raises(function() {
+ jQuery(jQuery.parseHTML( html, true )).appendTo("#qunit-fixture");
+ }, "Passing a script is allowed if allowScripts is true");
+
+ equal( jQuery.parseHTML("text")[0].nodeType, 3, "Parsing text returns a text node" );
+});
+
test("jQuery.parseJSON", function(){
expect(8);