diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-08-16 06:45:28 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-08-16 09:02:01 +0300 |
commit | b930d14ce64937e9478405eee2828d4da091d2cb (patch) | |
tree | 7966c17b5b66e02af5cfa485d3e6a565ef077645 /test/data | |
parent | 9d820fbde6d89bc7a06e2704be61cf6c0b4d6e3c (diff) | |
download | jquery-b930d14ce64937e9478405eee2828d4da091d2cb.tar.gz jquery-b930d14ce64937e9478405eee2828d4da091d2cb.zip |
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
Fixes gh-2540
Diffstat (limited to 'test/data')
-rw-r--r-- | test/data/testinit.js | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js index ef90fe45c..0dcb4f871 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -137,16 +137,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(); } @@ -160,7 +164,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 ) { @@ -170,7 +176,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 ); } @@ -179,7 +185,7 @@ this.ajaxTest = function( title, expect, options ) { }; if ( options.afterSend ) { - options.afterSend( request ); + options.afterSend( request, assert ); } return request @@ -202,7 +208,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(), @@ -211,10 +218,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; } @@ -233,11 +239,14 @@ this.testIframe = function( fileName, name, fn ) { }; this.testIframeWithCallback = function( title, fileName, func ) { - asyncTest( title, 1, function() { + QUnit.test( title, 1, function( assert ) { var iframe; + var done = assert.async(); window.iframeCallback = function() { - var args = arguments; + var args = Array.prototype.slice.call( arguments ); + + args.push( assert ); setTimeout(function() { this.iframeCallback = undefined; @@ -246,7 +255,7 @@ this.testIframeWithCallback = function( title, fileName, func ) { func.apply( this, args ); func = function() {}; - start(); + done(); }); }; iframe = jQuery( "<div/>" ).css({ position: "absolute", width: "500px", left: "-600px" }) |