2009-09-29 20:06:16 +02:00
|
|
|
var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
|
|
|
|
$ = this.$ || "$",
|
|
|
|
originaljQuery = jQuery,
|
2011-01-05 22:26:05 +01:00
|
|
|
original$ = $;
|
2009-09-29 20:11:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of elements with the given IDs, eg.
|
|
|
|
* @example q("main", "foo", "bar")
|
|
|
|
* @result [<div id="main">, <span id="foo">, <input id="bar">]
|
|
|
|
*/
|
|
|
|
function q() {
|
|
|
|
var r = [];
|
|
|
|
|
|
|
|
for ( var i = 0; i < arguments.length; i++ ) {
|
|
|
|
r.push( document.getElementById( arguments[i] ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
|
|
|
|
* @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baa
|
|
|
|
r'
|
|
|
|
*/
|
|
|
|
function t(a,b,c) {
|
2009-09-29 23:22:35 +02:00
|
|
|
var f = jQuery(b).get(), s = "";
|
2009-09-29 20:11:10 +02:00
|
|
|
|
|
|
|
for ( var i = 0; i < f.length; i++ ) {
|
|
|
|
s += (s && ",") + '"' + f[i].id + '"';
|
|
|
|
}
|
|
|
|
|
2009-09-29 23:22:35 +02:00
|
|
|
same(f, q.apply(q,c), a + " (" + b + ")");
|
2009-09-29 20:11:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add random number to url to stop IE from caching
|
|
|
|
*
|
|
|
|
* @example url("data/test.html")
|
|
|
|
* @result "data/test.html?10538358428943"
|
|
|
|
*
|
|
|
|
* @example url("data/test.php?foo=bar")
|
|
|
|
* @result "data/test.php?foo=bar&10538358345554"
|
|
|
|
*/
|
|
|
|
function url(value) {
|
|
|
|
return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
|
|
|
|
}
|
2011-01-09 22:58:47 +01:00
|
|
|
|
|
|
|
(function () {
|
|
|
|
// Store the old counts so that we only assert on tests that have actually leaked,
|
|
|
|
// instead of asserting every time a test has leaked sometime in the past
|
|
|
|
var oldCacheLength = 0,
|
|
|
|
oldFragmentsLength = 0,
|
|
|
|
oldTimersLength = 0,
|
|
|
|
oldActive = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures that tests have cleaned up properly after themselves. Should be passed as the
|
|
|
|
* teardown function on all modules' lifecycle object.
|
|
|
|
*/
|
|
|
|
this.moduleTeardown = function () {
|
|
|
|
var i, fragmentsLength = 0, cacheLength = 0;
|
|
|
|
|
|
|
|
// Allow QUnit.reset to clean up any attached elements before checking for leaks
|
|
|
|
QUnit.reset();
|
|
|
|
|
|
|
|
for ( i in jQuery.cache ) {
|
|
|
|
++cacheLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.fragments = {};
|
|
|
|
|
|
|
|
for ( i in jQuery.fragments ) {
|
|
|
|
++fragmentsLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test,
|
|
|
|
// if we unconditionally assert any of these, the test will fail with too many assertions :|
|
|
|
|
if ( cacheLength !== oldCacheLength ) {
|
|
|
|
equals( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" );
|
|
|
|
oldCacheLength = cacheLength;
|
|
|
|
}
|
|
|
|
if ( fragmentsLength !== oldFragmentsLength ) {
|
|
|
|
equals( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" );
|
|
|
|
oldFragmentsLength = fragmentsLength;
|
|
|
|
}
|
|
|
|
if ( jQuery.timers.length !== oldTimersLength ) {
|
|
|
|
equals( jQuery.timers.length, oldTimersLength, "No timers are still running" );
|
|
|
|
oldTimersLength = jQuery.timers.length;
|
|
|
|
}
|
|
|
|
if ( jQuery.active !== oldActive ) {
|
|
|
|
equals( jQuery.active, 0, "No AJAX requests are still active" );
|
|
|
|
oldActive = jQuery.active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}());
|