From be3b2b2d8b3c9647750be2e4bb4f9d4d7e6ec670 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 3 Sep 2014 08:37:51 -0400 Subject: [PATCH] Tests: Cleanup --- tests/jquery.js | 8 +++----- tests/unit/testsuite.js | 40 +++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tests/jquery.js b/tests/jquery.js index 5968cbfc2..67511667d 100644 --- a/tests/jquery.js +++ b/tests/jquery.js @@ -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( "=" ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index cb5397d57..18353c702 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -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(); + 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 ) { @@ -86,11 +90,11 @@ TestHelpers.testJshint = function( module ) { $.when( $.ajax({ - url: url("../../../ui/.jshintrc"), + url: url( "../../../ui/.jshintrc" ), dataType: "json" }), $.ajax({ - url: url("../../../ui/" + module + ".js"), + url: url( "../../../ui/" + module + ".js" ), dataType: "text" }) ).done(function( hintArgs, srcArgs ) { @@ -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" ); }); @@ -192,9 +198,9 @@ TestHelpers.commonWidgetTests = function( widget, settings ) { }); }; -TestHelpers.onFocus= function( element, onFocus ) { - var fn = function( event ){ - if( !event.originalEvent ) { +TestHelpers.onFocus = function( element, onFocus ) { + var fn = function( event ) { + if ( !event.originalEvent ) { return; } element.unbind( "focus", fn ); @@ -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 $( "
" ).css({ @@ -213,19 +220,17 @@ 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); + var passes = ( actual === expected ) || Math.abs( actual - expected ) <= maxDifference; + QUnit.push( passes, actual, expected, 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 ) { -- 2.39.5