mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Total revamping of the ajax unit tests
This commit is contained in:
parent
53a06660d8
commit
d31cef38f2
@ -38,6 +38,7 @@
|
|||||||
"stop": true,
|
"stop": true,
|
||||||
"expect": true,
|
"expect": true,
|
||||||
"raises": true,
|
"raises": true,
|
||||||
|
"ajaxTest": true,
|
||||||
"testIframe": true,
|
"testIframe": true,
|
||||||
"testIframeWithCallback": true,
|
"testIframeWithCallback": true,
|
||||||
"createDashboardXML": true,
|
"createDashboardXML": true,
|
||||||
@ -50,6 +51,7 @@
|
|||||||
"q": true,
|
"q": true,
|
||||||
"amdDefined": true,
|
"amdDefined": true,
|
||||||
"fireNative": true,
|
"fireNative": true,
|
||||||
|
"Globals": true,
|
||||||
"hasPHP": true,
|
"hasPHP": true,
|
||||||
"isLocal": true,
|
"isLocal": true,
|
||||||
"originaljQuery": true,
|
"originaljQuery": true,
|
||||||
|
@ -143,6 +143,77 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ajax testing helper
|
||||||
|
var ajaxTest = (function() {
|
||||||
|
|
||||||
|
var resolved = $.Deferred().resolve();
|
||||||
|
|
||||||
|
function getRequests( options ) {
|
||||||
|
var requests = options.requests || options.request || options || [];
|
||||||
|
if ( !jQuery.isArray(requests) ) {
|
||||||
|
requests = [ requests ];
|
||||||
|
}
|
||||||
|
return requests;
|
||||||
|
}
|
||||||
|
|
||||||
|
return function( title, expect, options ) {
|
||||||
|
if ( jQuery.isFunction(options) ) {
|
||||||
|
options = options();
|
||||||
|
}
|
||||||
|
options = options || [];
|
||||||
|
asyncTest( title, expect, function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
if ( options.setup ) {
|
||||||
|
options.setup();
|
||||||
|
}
|
||||||
|
var ajaxSettings = jQuery.ajaxSetup( {}, {} );
|
||||||
|
aborted = false,
|
||||||
|
abort = function( reason ) {
|
||||||
|
if ( !aborted ) {
|
||||||
|
aborted = true;
|
||||||
|
ok( false, "unexpected " + reason );
|
||||||
|
jQuery.each( requests, function( _, request ) {
|
||||||
|
request.abort();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
requestOptions = getRequests( options ),
|
||||||
|
requests = jQuery.map( requestOptions, function( options ) {
|
||||||
|
var request = ( options.create || jQuery.ajax )( options );
|
||||||
|
if ( options.afterSend ) {
|
||||||
|
options.afterSend( request );
|
||||||
|
}
|
||||||
|
return request;
|
||||||
|
});
|
||||||
|
requests = jQuery.map( requests, function( request, index ) {
|
||||||
|
function callIfDefined( type, type2 ) {
|
||||||
|
var handler = requestOptions[ index ][ type ] || !!requestOptions[ index ][ type2 ];
|
||||||
|
return handler ? function() {
|
||||||
|
if ( !aborted && jQuery.isFunction( handler ) ) {
|
||||||
|
handler.apply( this, arguments );
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
} : function() {
|
||||||
|
abort( type );
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var promise = request.then( callIfDefined( "done", "success" ), callIfDefined( "fail", "error" ) );
|
||||||
|
promise.abort = request.abort;
|
||||||
|
return promise;
|
||||||
|
});
|
||||||
|
jQuery.when.apply( jQuery, requests ).done(
|
||||||
|
options.teardown,
|
||||||
|
function() {
|
||||||
|
jQuery.ajaxSetup( ajaxSettings );
|
||||||
|
setTimeout( start, 0 );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, 0 );
|
||||||
|
});
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
this.testIframe = function( fileName, name, fn ) {
|
this.testIframe = function( fileName, name, fn ) {
|
||||||
|
@ -134,6 +134,31 @@ function testSubproject( label, url, risTests ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register globals for cleanup and the cleanup code itself
|
||||||
|
// Explanation at http://perfectionkills.com/understanding-delete/#ie_bugs
|
||||||
|
var Globals = (function() {
|
||||||
|
var globals = {};
|
||||||
|
return QUnit.config.noglobals ? {
|
||||||
|
register: function( name ) {
|
||||||
|
globals[ name ] = true;
|
||||||
|
jQuery.globalEval( "var " + name );
|
||||||
|
},
|
||||||
|
cleanup: function() {
|
||||||
|
var name,
|
||||||
|
current = globals;
|
||||||
|
globals = {};
|
||||||
|
for ( name in current ) {
|
||||||
|
jQuery.globalEval( "try { " +
|
||||||
|
"delete " + ( jQuery.support.deleteExpando ? "window['" + name + "']" : name ) +
|
||||||
|
"; } catch( x ) {}" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} : {
|
||||||
|
register: jQuery.noop,
|
||||||
|
cleanup: jQuery.noop
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* QUnit hooks
|
* QUnit hooks
|
||||||
*/
|
*/
|
||||||
@ -292,11 +317,14 @@ function testSubproject( label, url, risTests ) {
|
|||||||
// Reset internal jQuery state
|
// Reset internal jQuery state
|
||||||
jQuery.event.global = {};
|
jQuery.event.global = {};
|
||||||
if ( ajaxSettings ) {
|
if ( ajaxSettings ) {
|
||||||
jQuery.ajaxSettings = jQuery.extend( {}, ajaxSettings );
|
jQuery.ajaxSettings = jQuery.extend( true, {}, ajaxSettings );
|
||||||
} else {
|
} else {
|
||||||
delete jQuery.ajaxSettings;
|
delete jQuery.ajaxSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup globals
|
||||||
|
Globals.cleanup();
|
||||||
|
|
||||||
// Let QUnit reset the fixture
|
// Let QUnit reset the fixture
|
||||||
reset.apply( this, arguments );
|
reset.apply( this, arguments );
|
||||||
};
|
};
|
||||||
|
2890
test/unit/ajax.js
2890
test/unit/ajax.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user