Skip to content

Commit be3b2b2

Browse files
committed
Tests: Cleanup
1 parent 7f82fff commit be3b2b2

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

tests/jquery.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
(function() {
22

3-
var parts = document.location.search.slice( 1 ).split( "&" ),
3+
var current, version, url,
4+
parts = document.location.search.slice( 1 ).split( "&" ),
45
length = parts.length,
5-
i = 0,
6-
current,
7-
version,
8-
url;
6+
i = 0;
97

108
for ( ; i < length; i++ ) {
119
current = parts[ i ].split( "=" );

tests/unit/testsuite.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ function includeScript( url ) {
1313
}
1414

1515
function url( value ) {
16-
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random() * 100000, 10);
16+
return value + ( /\?/.test( value ) ? "&" : "?" ) + new Date().getTime() + "" +
17+
parseInt( Math.random() * 100000, 10 );
1718
}
1819

1920
reset = QUnit.reset;
2021
QUnit.reset = function() {
22+
2123
// Ensure jQuery events and data on the fixture are properly removed
22-
jQuery("#qunit-fixture").empty();
24+
jQuery( "#qunit-fixture" ).empty();
25+
2326
// Let QUnit reset the fixture
2427
reset.apply( this, arguments );
2528
};
@@ -54,7 +57,7 @@ TestHelpers.loadResources = QUnit.urlParams.min ?
5457
QUnit.config.urlConfig.push({
5558
id: "nojshint",
5659
label: "Skip JSHint",
57-
tooltip: "Skip running JSHint, e.g. within TestSwarm, where Jenkins runs it already"
60+
tooltip: "Skip running JSHint, e.g., within TestSwarm, where Jenkins runs it already"
5861
});
5962

6063
QUnit.config.urlConfig.push({
@@ -70,6 +73,7 @@ QUnit.config.urlConfig.push({
7073

7174
jshintLoaded = false;
7275
TestHelpers.testJshint = function( module ) {
76+
7377
// Function.prototype.bind check is needed because JSHint doesn't work in ES3 browsers anymore
7478
// https://github.com/jshint/jshint/issues/1384
7579
if ( QUnit.urlParams.nojshint || !Function.prototype.bind ) {
@@ -86,11 +90,11 @@ TestHelpers.testJshint = function( module ) {
8690

8791
$.when(
8892
$.ajax({
89-
url: url("../../../ui/.jshintrc"),
93+
url: url( "../../../ui/.jshintrc" ),
9094
dataType: "json"
9195
}),
9296
$.ajax({
93-
url: url("../../../ui/" + module + ".js"),
97+
url: url( "../../../ui/" + module + ".js" ),
9498
dataType: "text"
9599
})
96100
).done(function( hintArgs, srcArgs ) {
@@ -102,6 +106,7 @@ TestHelpers.testJshint = function( module ) {
102106
delete jshintrc.globals;
103107
passed = JSHINT( source, jshintrc, globals );
104108
errors = $.map( JSHINT.errors, function( error ) {
109+
105110
// JSHINT may report null if there are too many errors
106111
if ( !error ) {
107112
return;
@@ -123,7 +128,7 @@ TestHelpers.testJshint = function( module ) {
123128
function testWidgetDefaults( widget, defaults ) {
124129
var pluginDefaults = $.ui[ widget ].prototype.options;
125130

126-
// ensure that all defaults have the correct value
131+
// Ensure that all defaults have the correct value
127132
test( "defined defaults", function() {
128133
var count = 0;
129134
$.each( defaults, function( key, val ) {
@@ -136,7 +141,7 @@ function testWidgetDefaults( widget, defaults ) {
136141
});
137142
});
138143

139-
// ensure that all defaults were tested
144+
// Ensure that all defaults were tested
140145
test( "tested defaults", function() {
141146
var count = 0;
142147
$.each( pluginDefaults, function( key ) {
@@ -174,6 +179,7 @@ function testBasicUsage( widget ) {
174179
$( defaultElement )[ widget ]().remove();
175180
ok( true, "initialized on disconnected DOMElement - never connected" );
176181

182+
// Ensure manipulating removed elements works (#3664)
177183
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
178184
ok( true, "initialized on disconnected DOMElement - removed" );
179185
});
@@ -192,9 +198,9 @@ TestHelpers.commonWidgetTests = function( widget, settings ) {
192198
});
193199
};
194200

195-
TestHelpers.onFocus= function( element, onFocus ) {
196-
var fn = function( event ){
197-
if( !event.originalEvent ) {
201+
TestHelpers.onFocus = function( element, onFocus ) {
202+
var fn = function( event ) {
203+
if ( !event.originalEvent ) {
198204
return;
199205
}
200206
element.unbind( "focus", fn );
@@ -205,6 +211,7 @@ TestHelpers.onFocus= function( element, onFocus ) {
205211
};
206212

207213
TestHelpers.forceScrollableWindow = function( appendTo ) {
214+
208215
// The main testable area is 10000x10000 so to enforce scrolling,
209216
// this DIV must be greater than 10000 to work
210217
return $( "<div>" ).css({
@@ -213,19 +220,17 @@ TestHelpers.forceScrollableWindow = function( appendTo ) {
213220
}).appendTo( appendTo || "#qunit-fixture" );
214221
};
215222

216-
/*
217-
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
218-
*/
223+
// Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
219224
window.closeEnough = function( actual, expected, maxDifference, message ) {
220-
var passes = (actual === expected) || Math.abs(actual - expected) <= maxDifference;
221-
QUnit.push(passes, actual, expected, message);
225+
var passes = ( actual === expected ) || Math.abs( actual - expected ) <= maxDifference;
226+
QUnit.push( passes, actual, expected, message );
222227
};
223228

224229
/*
225230
* Experimental assertion for comparing DOM objects.
226231
*
227-
* Serializes an element and some properties and attributes and its children if any, otherwise the text.
228-
* Then compares the result using deepEqual.
232+
* Serializes an element and some properties and attributes and its children if any,
233+
* otherwise the text. Then compares the result using deepEqual().
229234
*/
230235
window.domEqual = function( selector, modifier, message ) {
231236
var expected, actual,
@@ -272,6 +277,7 @@ window.domEqual = function( selector, modifier, message ) {
272277
styles[ $.camelCase( key ) ] = style[ key ];
273278
}
274279
}
280+
275281
// support: Opera, IE <9
276282
} else {
277283
for ( key in style ) {

0 commit comments

Comments
 (0)