Skip to content

Commit 0c18520

Browse files
committed
No ticket: Hide the testing-support jQuery from tests
1 parent f66d53c commit 0c18520

File tree

6 files changed

+41
-32
lines changed

6 files changed

+41
-32
lines changed

test/.jshintrc

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"ajaxTest": false,
3939
"testIframe": false,
4040
"testIframeWithCallback": false,
41+
"iframeCallback": true,
4142
"createDashboardXML": false,
4243
"createXMLFragment": false,
4344
"moduleTeardown": false,
@@ -54,6 +55,7 @@
5455
"Globals": true,
5556
"hasPHP": true,
5657
"isLocal": true,
58+
"supportjQuery": true,
5759
"originaljQuery": true,
5860
"$": true,
5961
"original$": true,

test/data/testinit.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*jshint multistr:true, quotmark:false */
22

3-
var fireNative,
4-
originaljQuery = this.jQuery || "jQuery",
5-
original$ = this.$ || "$",
3+
var fireNative, originaljQuery, original$,
4+
supportjQuery = this.jQuery,
65
// see RFC 2606
76
externalHost = "example.com";
87

98
this.hasPHP = true;
109
this.isLocal = window.location.protocol === "file:";
1110

12-
// For testing .noConflict()
13-
this.jQuery = originaljQuery;
14-
this.$ = original$;
11+
// Setup global variables before loading jQuery for testing .noConflict()
12+
supportjQuery.noConflict( true );
13+
originaljQuery = this.jQuery = undefined;
14+
original$ = this.$ = "replaced";
1515

1616
/**
1717
* Returns an array of elements with the given IDs
@@ -253,3 +253,4 @@ this.testIframeWithCallback = function( title, fileName, func ) {
253253
).appendTo( "body" );
254254
});
255255
};
256+
this.iframeCallback = undefined;

test/data/testrunner.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
/**
2-
* Allow the test suite to run with other libs or jQuery's.
3-
*/
4-
jQuery.noConflict();
1+
if ( typeof jQuery !== "undefined" ) {
2+
/**
3+
* Allow the test suite to run with other libs or jQuery's.
4+
*/
5+
jQuery.noConflict();
6+
7+
// Expose Sizzle for Sizzle's selector tests
8+
// We remove Sizzle's globalization in jQuery
9+
this.Sizzle = this.Sizzle || jQuery.find;
10+
}
511

612
// For checking globals pollution despite auto-created globals in various environments
7-
jQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
13+
supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
814
window[ name ] = window[ name ];
915
});
1016

11-
// Expose Sizzle for Sizzle's selector tests
12-
// We remove Sizzle's globalization in jQuery
13-
var Sizzle = Sizzle || jQuery.find,
14-
1517
// Allow subprojects to test against their own fixtures
16-
qunitModule = QUnit.module,
18+
var qunitModule = QUnit.module,
1719
qunitTest = QUnit.test;
1820

1921
/**
@@ -53,7 +55,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
5355

5456
// Find test function and wrap to require subproject fixture
5557
for ( ; i >= 0; i-- ) {
56-
if ( originaljQuery.isFunction( args[i] ) ) {
58+
if ( supportjQuery.isFunction( args[i] ) ) {
5759
args[i] = requireFixture( args[i] );
5860
break;
5961
}
@@ -64,15 +66,15 @@ this.testSubproject = function( label, url, risTests, complete ) {
6466

6567
// Load tests and fixture from subproject
6668
// Test order matters, so we must be synchronous and throw an error on load failure
67-
originaljQuery.ajax( url, {
69+
supportjQuery.ajax( url, {
6870
async: false,
6971
dataType: "html",
7072
error: function( jqXHR, status ) {
7173
throw new Error( "Could not load: " + url + " (" + status + ")" );
7274
},
7375
success: function( data, status, jqXHR ) {
7476
var sources = [],
75-
page = originaljQuery.parseHTML(
77+
page = supportjQuery.parseHTML(
7678
// replace html/head with dummy elements so they are represented in the DOM
7779
( data || "" ).replace( /<\/?((!DOCTYPE|html|head)\b.*?)>/gi, "[$1]" ),
7880
document,
@@ -82,11 +84,11 @@ this.testSubproject = function( label, url, risTests, complete ) {
8284
if ( !page || !page.length ) {
8385
this.error( jqXHR, "no data" );
8486
}
85-
page = originaljQuery( page );
87+
page = supportjQuery( page );
8688

8789
// Include subproject tests
8890
page.filter("script[src]").add( page.find("script[src]") ).map(function() {
89-
var src = originaljQuery( this ).attr("src");
91+
var src = supportjQuery( this ).attr("src");
9092
if ( risTests.test( src ) ) {
9193
sources.push( src );
9294
}
@@ -123,7 +125,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
123125
}
124126

125127
// Replace the current fixture, including content outside of #qunit-fixture
126-
var oldFixture = originaljQuery("#qunit-fixture");
128+
var oldFixture = supportjQuery("#qunit-fixture");
127129
while ( oldFixture.length && !oldFixture.prevAll("[id='qunit']").length ) {
128130
oldFixture = oldFixture.parent();
129131
}
@@ -133,7 +135,7 @@ this.testSubproject = function( label, url, risTests, complete ) {
133135
// WARNING: UNDOCUMENTED INTERFACE
134136
QUnit.config.fixture = fixtureHTML;
135137
QUnit.reset();
136-
if ( originaljQuery("#qunit-fixture").html() !== fixtureHTML ) {
138+
if ( supportjQuery("#qunit-fixture").html() !== fixtureHTML ) {
137139
ok( false, "Copied subproject fixture" );
138140
return;
139141
}
@@ -153,15 +155,15 @@ this.Globals = (function() {
153155
return {
154156
register: function( name ) {
155157
globals[ name ] = true;
156-
jQuery.globalEval( "var " + name + " = undefined;" );
158+
supportjQuery.globalEval( "var " + name + " = undefined;" );
157159
},
158160
cleanup: function() {
159161
var name,
160162
current = globals;
161163
globals = {};
162164
for ( name in current ) {
163-
jQuery.globalEval( "try { " +
164-
"delete " + ( jQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
165+
supportjQuery.globalEval( "try { " +
166+
"delete " + ( supportjQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
165167
"; } catch( x ) {}" );
166168
}
167169
}
@@ -223,7 +225,7 @@ this.Globals = (function() {
223225
if ( elems.jquery && elems.toArray ) {
224226
elems = elems.toArray();
225227
}
226-
if ( !jQuery.isArray( elems ) ) {
228+
if ( !supportjQuery.isArray( elems ) ) {
227229
elems = [ elems ];
228230
}
229231

@@ -341,14 +343,16 @@ this.Globals = (function() {
341343

342344
QUnit.done(function() {
343345
// Remove our own fixtures outside #qunit-fixture
344-
jQuery("#qunit ~ *").remove();
346+
supportjQuery("#qunit ~ *").remove();
345347
});
346348

347349
// jQuery-specific QUnit.reset
348350
QUnit.reset = function() {
349351

350352
// Ensure jQuery events and data on the fixture are properly removed
351353
jQuery("#qunit-fixture").empty();
354+
// ...even if the jQuery under test has a broken .empty()
355+
supportjQuery("#qunit-fixture").empty();
352356

353357
// Reset internal jQuery state
354358
jQuery.event.global = {};

test/unit/attributes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test( "attr(String)", function() {
9696
jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture");
9797
equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
9898

99-
$("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
99+
jQuery("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
100100
equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
101101

102102
// list attribute is readonly by default in browsers that support it

test/unit/core.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,9 @@ asyncTest("isPlainObject", function() {
351351
ok( pass, "Does not throw exceptions on host objects" );
352352

353353
// Objects from other windows should be matched
354-
window.iframeCallback = function( otherObject, detail ) {
355-
window.iframeCallback = undefined;
354+
Globals.register("iframeDone");
355+
window.iframeDone = function( otherObject, detail ) {
356+
window.iframeDone = undefined;
356357
iframe.parentNode.removeChild( iframe );
357358
ok( jQuery.isPlainObject(new otherObject()), "new otherObject" + ( detail ? " - " + detail : "" ) );
358359
start();
@@ -362,7 +363,7 @@ asyncTest("isPlainObject", function() {
362363
iframe = jQuery("#qunit-fixture")[0].appendChild( document.createElement("iframe") );
363364
doc = iframe.contentDocument || iframe.contentWindow.document;
364365
doc.open();
365-
doc.write("<body onload='window.parent.iframeCallback(Object);'>");
366+
doc.write("<body onload='window.parent.iframeDone(Object);'>");
366367
doc.close();
367368
} catch(e) {
368369
window.iframeDone( Object, "iframes not supported" );

test/unit/event.js

+1
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,7 @@ test("focus-blur order (#12868)", function() {
23802380
// Run handlers without native method on an input
23812381
order = 1;
23822382
$radio.triggerHandler( "focus" );
2383+
$text.off();
23832384
start();
23842385
}, 50 );
23852386
}, 50 );

0 commit comments

Comments
 (0)