From 4543815eeda0d7299e701311ca4ac38f23dbaf3a Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Thu, 3 Sep 2015 04:46:31 +0300 Subject: [PATCH] Tests: Partially use new qunit interface http://qunitjs.com/upgrade-guide-2.x/ For most of the boring work was used https://github.com/apsdehal/qunit-migrate package However, it can't update local qunit helpers, plus in some places old QUnit.asyncTest signature is still used Ref b930d14ce64937e9478405eee2828d4da091d2cb Fixes gh-2540 --- test/data/testinit.js | 72 +- test/unit/ajax.js | 2329 ++++++++++++++++++------------------- test/unit/animation.js | 201 ++-- test/unit/attributes.js | 986 ++++++++-------- test/unit/callbacks.js | 130 +-- test/unit/core.js | 1046 +++++++++-------- test/unit/css.js | 623 +++++----- test/unit/data.js | 1022 ++++++++++------ test/unit/deferred.js | 196 ++-- test/unit/deprecated.js | 2 +- test/unit/dimensions.js | 374 +++--- test/unit/effects.js | 902 +++++++------- test/unit/event.js | 1115 +++++++++--------- test/unit/exports.js | 8 +- test/unit/manipulation.js | 1358 ++++++++++----------- test/unit/offset.js | 326 +++--- test/unit/queue.js | 174 +-- test/unit/ready.js | 30 +- test/unit/selector.js | 336 +++--- test/unit/serialize.js | 78 +- test/unit/support.js | 72 +- test/unit/traversing.js | 796 ++++++------- test/unit/tween.js | 285 +++-- test/unit/wrap.js | 295 +++-- 24 files changed, 6640 insertions(+), 6116 deletions(-) diff --git a/test/data/testinit.js b/test/data/testinit.js index 273436cf9..491440e19 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -17,7 +17,7 @@ original$ = this.$ = "replaced"; /** * Returns an array of elements with the given IDs - * @example q("main", "foo", "bar") + * @example q( "main", "foo", "bar" ) * @result [
, , ] */ this.q = function() { @@ -114,12 +114,12 @@ this.createXMLFragment = function() { fireNative = document.createEvent ? function( node, type ) { var event = document.createEvent( "HTMLEvents" ); + event.initEvent( type, true, true ); node.dispatchEvent( event ); } : function( node, type ) { - var event = document.createEventObject(); - node.fireEvent( "on" + type, event ); + node.fireEvent( "on" + type, document.createEventObject() ); }; /** @@ -138,16 +138,20 @@ function url( value ) { // Ajax testing helper this.ajaxTest = function( title, expect, options ) { - var requestOptions; - if ( jQuery.isFunction( options ) ) { - options = options(); - } - options = options || []; - requestOptions = options.requests || options.request || options; - if ( !jQuery.isArray( requestOptions ) ) { - requestOptions = [ requestOptions ]; - } - asyncTest( title, expect, function() { + QUnit.test( title, expect, function( assert ) { + var requestOptions; + + if ( jQuery.isFunction( options ) ) { + options = options( assert ); + } + options = options || []; + requestOptions = options.requests || options.request || options; + if ( !jQuery.isArray( requestOptions ) ) { + requestOptions = [ requestOptions ]; + } + + var done = assert.async(); + if ( options.setup ) { options.setup(); } @@ -161,7 +165,9 @@ this.ajaxTest = function( title, expect, options ) { if ( options.teardown ) { options.teardown(); } - start(); + + // Make sure all events will be called before done() + setTimeout( done ); } }, requests = jQuery.map( requestOptions, function( options ) { @@ -171,7 +177,7 @@ this.ajaxTest = function( title, expect, options ) { return function( _, status ) { if ( !completed ) { if ( !handler ) { - ok( false, "unexpected " + status ); + assert.ok( false, "unexpected " + status ); } else if ( jQuery.isFunction( handler ) ) { handler.apply( this, arguments ); } @@ -180,7 +186,7 @@ this.ajaxTest = function( title, expect, options ) { }; if ( options.afterSend ) { - options.afterSend( request ); + options.afterSend( request, assert ); } return request @@ -203,7 +209,8 @@ this.ajaxTest = function( title, expect, options ) { }; this.testIframe = function( fileName, name, fn ) { - asyncTest( name, function() { + QUnit.test( name, function( assert ) { + var done = assert.async(); // load fixture in iframe var iframe = loadFixture(), @@ -212,10 +219,9 @@ this.testIframe = function( fileName, name, fn ) { if ( win && win.jQuery && win.jQuery.isReady ) { clearInterval( interval ); - start(); - // call actual tests passing the correct jQuery instance to use - fn.call( this, win.jQuery, win, win.document ); + fn.call( this, win.jQuery, win, win.document, assert ); + done(); document.body.removeChild( iframe ); iframe = null; } @@ -234,31 +240,31 @@ this.testIframe = function( fileName, name, fn ) { }; this.testIframeWithCallback = function( title, fileName, func ) { - - test( title, function() { + QUnit.test( title, 1, function( assert ) { var iframe; + var done = assert.async(); - // Expect one assertion, but allow overrides - expect( 1 ); - - stop(); window.iframeCallback = function() { - var self = this, - args = arguments; + var args = Array.prototype.slice.call( arguments ); + + args.push( assert ); + setTimeout( function() { - window.iframeCallback = undefined; + this.iframeCallback = undefined; + iframe.remove(); - func.apply( self, args ); + func.apply( this, args ); func = function() {}; - start(); - }, 0 ); + + done(); + } ); }; iframe = jQuery( "
" ).css( { position: "absolute", width: "500px", left: "-600px" } ) .append( jQuery( "