@@ -743,6 +743,58 @@ QUnit.test( "contents()", function( assert ) {
743743 assert . equal ( c [ 0 ] . nodeValue , "hi" , "Check node,textnode,comment contents is just the one from span" ) ;
744744} ) ;
745745
746+ QUnit . test ( "contents() for <template />" , function ( assert ) {
747+ assert . expect ( 4 ) ;
748+
749+ jQuery ( "#qunit-fixture" ) . append (
750+ "<template id='template'>" +
751+ " <div id='template-div0'>" +
752+ " <span>Hello, Web Component!</span>" +
753+ " </div>" +
754+ " <div id='template-div1'></div>" +
755+ " <div id='template-div2'></div>" +
756+ "</template>"
757+ ) ;
758+
759+ var contents = jQuery ( "#template" ) . contents ( ) ;
760+ assert . equal ( contents . length , 6 , "Check template element contents" ) ;
761+
762+ assert . equal ( contents . find ( "span" ) . text ( ) , "Hello, Web Component!" , "Find span in template and check its text" ) ;
763+
764+ jQuery ( "<div id='templateTest' />" ) . append (
765+ jQuery ( jQuery . map ( contents , function ( node ) {
766+ return document . importNode ( node , true ) ;
767+ } ) )
768+ ) . appendTo ( "#qunit-fixture" ) ;
769+
770+ contents = jQuery ( "#templateTest" ) . contents ( ) ;
771+ assert . equal ( contents . length , 6 , "Check cloned nodes of template element contents" ) ;
772+
773+ assert . equal ( contents . filter ( "div" ) . length , 3 , "Count cloned elements from template" ) ;
774+ } ) ;
775+
776+ QUnit [ "content" in document . createElement ( "template" ) ? "test" : "skip" ] (
777+ "contents() for <template /> remains inert" ,
778+ function ( assert ) {
779+ assert . expect ( 2 ) ;
780+
781+ Globals . register ( "testScript" ) ;
782+ Globals . register ( "testImgOnload" ) ;
783+
784+ jQuery ( "#qunit-fixture" ) . append (
785+ "<template id='template'>" +
786+ " <script>testScript = 1;</script>" +
787+ " <img src='data/1x1.jpg' onload='testImgOnload = 1' >" +
788+ "</template>"
789+ ) ;
790+
791+ var content = jQuery ( "#template" ) . contents ( ) ;
792+
793+ assert . strictEqual ( window . testScript , true , "script in template isn't executed" ) ;
794+ assert . strictEqual ( window . testImgOnload , true , "onload of image in template isn't executed" ) ;
795+ }
796+ ) ;
797+
746798QUnit . test ( "sort direction" , function ( assert ) {
747799 assert . expect ( 12 ) ;
748800
0 commit comments