Tests: Cleanup

This commit is contained in:
Scott González 2014-09-03 08:37:51 -04:00
parent 7f82fffbe9
commit be3b2b2d8b
2 changed files with 26 additions and 22 deletions

8
tests/jquery.js vendored
View File

@ -1,11 +1,9 @@
(function() {
var parts = document.location.search.slice( 1 ).split( "&" ),
var current, version, url,
parts = document.location.search.slice( 1 ).split( "&" ),
length = parts.length,
i = 0,
current,
version,
url;
i = 0;
for ( ; i < length; i++ ) {
current = parts[ i ].split( "=" );

View File

@ -13,13 +13,16 @@ function includeScript( url ) {
}
function url( value ) {
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random() * 100000, 10);
return value + ( /\?/.test( value ) ? "&" : "?" ) + new Date().getTime() + "" +
parseInt( Math.random() * 100000, 10 );
}
reset = QUnit.reset;
QUnit.reset = function() {
// Ensure jQuery events and data on the fixture are properly removed
jQuery( "#qunit-fixture" ).empty();
// Let QUnit reset the fixture
reset.apply( this, arguments );
};
@ -54,7 +57,7 @@ TestHelpers.loadResources = QUnit.urlParams.min ?
QUnit.config.urlConfig.push({
id: "nojshint",
label: "Skip JSHint",
tooltip: "Skip running JSHint, e.g. within TestSwarm, where Jenkins runs it already"
tooltip: "Skip running JSHint, e.g., within TestSwarm, where Jenkins runs it already"
});
QUnit.config.urlConfig.push({
@ -70,6 +73,7 @@ QUnit.config.urlConfig.push({
jshintLoaded = false;
TestHelpers.testJshint = function( module ) {
// Function.prototype.bind check is needed because JSHint doesn't work in ES3 browsers anymore
// https://github.com/jshint/jshint/issues/1384
if ( QUnit.urlParams.nojshint || !Function.prototype.bind ) {
@ -102,6 +106,7 @@ TestHelpers.testJshint = function( module ) {
delete jshintrc.globals;
passed = JSHINT( source, jshintrc, globals );
errors = $.map( JSHINT.errors, function( error ) {
// JSHINT may report null if there are too many errors
if ( !error ) {
return;
@ -123,7 +128,7 @@ TestHelpers.testJshint = function( module ) {
function testWidgetDefaults( widget, defaults ) {
var pluginDefaults = $.ui[ widget ].prototype.options;
// ensure that all defaults have the correct value
// Ensure that all defaults have the correct value
test( "defined defaults", function() {
var count = 0;
$.each( defaults, function( key, val ) {
@ -136,7 +141,7 @@ function testWidgetDefaults( widget, defaults ) {
});
});
// ensure that all defaults were tested
// Ensure that all defaults were tested
test( "tested defaults", function() {
var count = 0;
$.each( pluginDefaults, function( key ) {
@ -174,6 +179,7 @@ function testBasicUsage( widget ) {
$( defaultElement )[ widget ]().remove();
ok( true, "initialized on disconnected DOMElement - never connected" );
// Ensure manipulating removed elements works (#3664)
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
ok( true, "initialized on disconnected DOMElement - removed" );
});
@ -205,6 +211,7 @@ TestHelpers.onFocus= function( element, onFocus ) {
};
TestHelpers.forceScrollableWindow = function( appendTo ) {
// The main testable area is 10000x10000 so to enforce scrolling,
// this DIV must be greater than 10000 to work
return $( "<div>" ).css({
@ -213,9 +220,7 @@ TestHelpers.forceScrollableWindow = function( appendTo ) {
}).appendTo( appendTo || "#qunit-fixture" );
};
/*
* Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
*/
// Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
window.closeEnough = function( actual, expected, maxDifference, message ) {
var passes = ( actual === expected ) || Math.abs( actual - expected ) <= maxDifference;
QUnit.push( passes, actual, expected, message );
@ -224,8 +229,8 @@ window.closeEnough = function( actual, expected, maxDifference, message ) {
/*
* Experimental assertion for comparing DOM objects.
*
* Serializes an element and some properties and attributes and its children if any, otherwise the text.
* Then compares the result using deepEqual.
* Serializes an element and some properties and attributes and its children if any,
* otherwise the text. Then compares the result using deepEqual().
*/
window.domEqual = function( selector, modifier, message ) {
var expected, actual,
@ -272,6 +277,7 @@ window.domEqual = function( selector, modifier, message ) {
styles[ $.camelCase( key ) ] = style[ key ];
}
}
// support: Opera, IE <9
} else {
for ( key in style ) {