]> source.dussan.org Git - jquery.git/commitdiff
Tests: Attach test iframes to the body for visibility-dependent code
authorRichard Gibson <richard.gibson@gmail.com>
Tue, 25 Apr 2017 19:39:41 +0000 (15:39 -0400)
committerGitHub <noreply@github.com>
Tue, 25 Apr 2017 19:39:41 +0000 (15:39 -0400)
Ref 1d2df772b4d6e5dbf91df6e75f4a1809f7879ab0
Closes gh-3645

test/data/testinit.js
test/data/testrunner.js

index dd06f86bea6609080ee61a526ff46472d82c2e46..c55ebd1bb817dee6f612dacd9a4046de1f38ac64 100644 (file)
@@ -233,8 +233,10 @@ this.ajaxTest = function( title, expect, options ) {
 
 this.testIframe = function( title, fileName, func ) {
        QUnit.test( title, function( assert ) {
-               var iframe;
-               var done = assert.async();
+               var done = assert.async(),
+                       $iframe = supportjQuery( "<iframe/>" )
+                               .css( { position: "absolute", width: "500px", left: "-600px" } )
+                               .attr( { id: "qunit-fixture-iframe", src: url( "./data/" + fileName ) } );
 
                // Test iframes are expected to invoke this via startIframeTest (cf. iframeTest.js)
                window.iframeCallback = function() {
@@ -247,13 +249,14 @@ this.testIframe = function( title, fileName, func ) {
 
                                func.apply( this, args );
                                func = function() {};
-                               iframe.remove();
+                               $iframe.remove();
                                done();
                        } );
                };
-               iframe = jQuery( "<div/>" ).css( { position: "absolute", width: "500px", left: "-600px" } )
-                       .append( jQuery( "<iframe/>" ).attr( "src", url( "./data/" + fileName ) ) )
-                       .appendTo( "#qunit-fixture" );
+
+               // Attach iframe to the body for visibility-dependent code
+               // It will be removed by either the above code, or the testDone callback in testrunner.js
+               $iframe.appendTo( document.body );
        } );
 };
 this.iframeCallback = undefined;
index 0784ae0a82431c8432879209e67a6b4dfc48986a..b8f1127ab47bc2dddefc6834a7b4506cfe3b540e 100644 (file)
@@ -167,6 +167,9 @@ QUnit.testDone( function() {
        // ...even if the jQuery under test has a broken .empty()
        supportjQuery( "#qunit-fixture" ).empty();
 
+       // Remove the iframe fixture
+       supportjQuery( "#qunit-fixture-iframe" ).remove();
+
        // Reset internal jQuery state
        jQuery.event.global = {};
        if ( ajaxSettings ) {