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( "