]> source.dussan.org Git - jquery.git/commitdiff
No ticket: Hide the testing-support jQuery from tests
authorRichard Gibson <richard.gibson@gmail.com>
Tue, 3 Sep 2013 13:55:32 +0000 (09:55 -0400)
committerRichard Gibson <richard.gibson@gmail.com>
Tue, 3 Sep 2013 15:13:20 +0000 (11:13 -0400)
(cherry picked from commit 0c185209233f4c15e57c6a24e8f81b27dd26db59)

Conflicts:

test/data/testrunner.js

test/.jshintrc
test/data/testinit.js
test/data/testrunner.js
test/unit/attributes.js
test/unit/core.js
test/unit/event.js
test/unit/manipulation.js

index f974f8e4b2ef3fcd005ebdb36ffef75d88584b24..34f8a5b2dcf787c297fd2fb92b2a2be88a7e715c 100644 (file)
@@ -38,6 +38,7 @@
                "ajaxTest": false,
                "testIframe": false,
                "testIframeWithCallback": false,
+               "iframeCallback": true,
                "createDashboardXML": false,
                "createXMLFragment": false,
                "moduleTeardown": false,
@@ -54,6 +55,7 @@
                "Globals": true,
                "hasPHP": true,
                "isLocal": true,
+               "supportjQuery": true,
                "originaljQuery": true,
                "$": true,
                "original$": true,
index 30136de36757484497700ef8fe1e6a4ebabb6915..8cb57d5f54c1214097120f9960142e70906d7bc9 100644 (file)
@@ -1,17 +1,17 @@
 /*jshint multistr:true, quotmark:false */
 
-var fireNative,
-       originaljQuery = this.jQuery || "jQuery",
-       original$ = this.$ || "$",
+var fireNative, originaljQuery, original$,
+       supportjQuery = this.jQuery,
        // see RFC 2606
        externalHost = "example.com";
 
 this.hasPHP = true;
 this.isLocal = window.location.protocol === "file:";
 
-// For testing .noConflict()
-this.jQuery = originaljQuery;
-this.$ = original$;
+// Setup global variables before loading jQuery for testing .noConflict()
+supportjQuery.noConflict( true );
+originaljQuery = this.jQuery = undefined;
+original$ = this.$ = "replaced";
 
 /**
  * Returns an array of elements with the given IDs
@@ -253,3 +253,4 @@ this.testIframeWithCallback = function( title, fileName, func ) {
                ).appendTo( "body" );
        });
 };
+this.iframeCallback = undefined;
index 8ddb0544a339a1f21a27136cce42a3ea7436a4db..ea0eb014e7cc8576cbc62eaa971a58d12092bfb3 100644 (file)
@@ -1,19 +1,21 @@
-/**
- * Allow the test suite to run with other libs or jQuery's.
- */
-jQuery.noConflict();
+if ( typeof jQuery !== "undefined" ) {
+       /**
+        * Allow the test suite to run with other libs or jQuery's.
+        */
+       jQuery.noConflict();
+       
+       // Expose Sizzle for Sizzle's selector tests
+       // We remove Sizzle's globalization in jQuery
+       this.Sizzle = this.Sizzle || jQuery.find;
+}
 
 // For checking globals pollution despite auto-created globals in various environments
-jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
+supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
        window[ name ] = window[ name ];
 });
 
-// Expose Sizzle for Sizzle's selector tests
-// We remove Sizzle's globalization in jQuery
-var Sizzle = Sizzle || jQuery.find,
-
 // Allow subprojects to test against their own fixtures
-       qunitModule = QUnit.module,
+var qunitModule = QUnit.module,
        qunitTest = QUnit.test;
 
 /**
@@ -53,7 +55,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
 
                // Find test function and wrap to require subproject fixture
                for ( ; i >= 0; i-- ) {
-                       if ( originaljQuery.isFunction( args[i] ) ) {
+                       if ( supportjQuery.isFunction( args[i] ) ) {
                                args[i] = requireFixture( args[i] );
                                break;
                        }
@@ -64,7 +66,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
 
        // Load tests and fixture from subproject
        // Test order matters, so we must be synchronous and throw an error on load failure
-       originaljQuery.ajax( url, {
+       supportjQuery.ajax( url, {
                async: false,
                dataType: "html",
                error: function( jqXHR, status ) {
@@ -72,7 +74,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
                },
                success: function( data, status, jqXHR ) {
                        var sources = [],
-                               page = originaljQuery.parseHTML(
+                               page = supportjQuery.parseHTML(
                                // replace html/head with dummy elements so they are represented in the DOM
                                ( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ),
                                document,
@@ -82,11 +84,11 @@ this.testSubproject = function( label, url, risTests, complete ) {
                        if ( !page || !page.length ) {
                                this.error( jqXHR, "no data" );
                        }
-                       page = originaljQuery( page );
+                       page = supportjQuery( page );
 
                        // Include subproject tests
                        page.filter("script[src]").add( page.find("script[src]") ).map(function() {
-                               var src = originaljQuery( this ).attr("src");
+                               var src = supportjQuery( this ).attr("src");
                                if ( risTests.test( src ) ) {
                                        sources.push( src );
                                }
@@ -123,7 +125,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
                                }
 
                                // Replace the current fixture, including content outside of #qunit-fixture
-                               var oldFixture = originaljQuery("#qunit-fixture");
+                               var oldFixture = supportjQuery("#qunit-fixture");
                                while ( oldFixture.length && !oldFixture.prevAll("[id='qunit']").length ) {
                                        oldFixture = oldFixture.parent();
                                }
@@ -133,7 +135,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
                                // WARNING: UNDOCUMENTED INTERFACE
                                QUnit.config.fixture = fixtureHTML;
                                QUnit.reset();
-                               if ( originaljQuery("#qunit-fixture").html() !== fixtureHTML ) {
+                               if ( supportjQuery("#qunit-fixture").html() !== fixtureHTML ) {
                                        ok( false, "Copied subproject fixture" );
                                        return;
                                }
@@ -153,15 +155,15 @@ this.Globals = (function() {
        return {
                register: function( name ) {
                        globals[ name ] = true;
-                       jQuery.globalEval( "var " + name + " = undefined;" );
+                       supportjQuery.globalEval( "var " + name + " = undefined;" );
                },
                cleanup: function() {
                        var name,
                                current = globals;
                        globals = {};
                        for ( name in current ) {
-                               jQuery.globalEval( "try { " +
-                                       "delete " + ( jQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
+                               supportjQuery.globalEval( "try { " +
+                                       "delete " + ( supportjQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
                                "; } catch( x ) {}" );
                        }
                }
@@ -335,7 +337,7 @@ this.Globals = (function() {
 
        QUnit.done(function() {
                // Remove our own fixtures outside #qunit-fixture
-               jQuery("#qunit ~ *").remove();
+               supportjQuery("#qunit ~ *").remove();
        });
 
        // jQuery-specific QUnit.reset
@@ -343,6 +345,8 @@ this.Globals = (function() {
 
                // Ensure jQuery events and data on the fixture are properly removed
                jQuery("#qunit-fixture").empty();
+               // ...even if the jQuery under test has a broken .empty()
+               supportjQuery("#qunit-fixture").empty();
 
                // Reset internal jQuery state
                jQuery.event.global = {};
index dc34f9df7e3af1d9e3db704069a3d82e02599ee9..bef1fa23618bba2a724a313115b035c0feddd77e 100644 (file)
@@ -100,7 +100,7 @@ test( "attr(String)", function() {
        jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture");
        equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
 
-       $("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
+       jQuery("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
        equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
 
        // list attribute is readonly by default in browsers that support it
index e57d5333478b00122c3a6807362631cd0adde2ff..cdc4c65287d119cf5d1b3ef9792d8d53614313fd 100644 (file)
@@ -353,8 +353,9 @@ asyncTest("isPlainObject", function() {
        ok( pass, "Does not throw exceptions on host objects" );
 
        // Objects from other windows should be matched
-       window.iframeCallback = function( otherObject, detail ) {
-               window.iframeCallback = undefined;
+       Globals.register("iframeDone");
+       window.iframeDone = function( otherObject, detail ) {
+               window.iframeDone = undefined;
                iframe.parentNode.removeChild( iframe );
                ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
                start();
@@ -364,7 +365,7 @@ asyncTest("isPlainObject", function() {
                iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
                doc = iframe.contentDocument || iframe.contentWindow.document;
                doc.open();
-               doc.write("<body onload='window.parent.iframeCallback(Object);'>");
+               doc.write("<body onload='window.parent.iframeDone(Object);'>");
                doc.close();
        } catch(e) {
                window.iframeDone( Object, "iframes not supported" );
index 1b65f99def860ae4c117fecbe7ca05d21dc68dbd..bbb60fd2574760286bd15d767357aa47741e42fe 100644 (file)
@@ -2453,6 +2453,7 @@ test("focus-blur order (#12868)", function() {
                        // Run handlers without native method on an input
                        order = 1;
                        $radio.triggerHandler( "focus" );
+                       $text.off();
                        start();
                }, 50 );
        }, 50 );
index 6a685114243ab47f3ef566648108b66a88980293..f5a5de853dec4162e3a97a1c7c2a370c56ecccf3 100644 (file)
@@ -1681,11 +1681,11 @@ test("empty()", function() {
        equal( j.html(), "", "Check node,textnode,comment empty works" );
 
        // Ensure oldIE empties selects (#12336)
-       notEqual( $("#select1").find("option").length, 0, "Have some initial options" );
-       $("#select1").empty();
-       equal( $("#select1").find("option").length, 0, "No more option elements found" );
-       equal( $("#select1")[0].options.length, 0, "options.length cleared as well" );
-       });
+       notEqual( jQuery("#select1").find("option").length, 0, "Have some initial options" );
+       jQuery("#select1").empty();
+       equal( jQuery("#select1").find("option").length, 0, "No more option elements found" );
+       equal( jQuery("#select1")[0].options.length, 0, "options.length cleared as well" );
+});
 
 test( "jQuery.cleanData", function() {