1 var jQuery
= this.jQuery
|| "jQuery", // For testing .noConflict()
3 originaljQuery
= jQuery
,
7 * Returns an array of elements with the given IDs, eg.
8 * @example q("main", "foo", "bar")
9 * @result [<div id="main">, <span id="foo">, <input id="bar">]
14 for ( var i
= 0; i
< arguments
.length
; i
++ ) {
15 r
.push( document
.getElementById( arguments
[i
] ) );
22 * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
23 * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baa
27 var f
= jQuery(b
).get(), s
= "";
29 for ( var i
= 0; i
< f
.length
; i
++ ) {
30 s
+= (s
&& ",") + '"' + f
[i
].id
+ '"';
33 same(f
, q
.apply(q
,c
), a
+ " (" + b
+ ")");
37 * Add random number to url to stop IE from caching
39 * @example url("data/test.html")
40 * @result "data/test.html?10538358428943"
42 * @example url("data/test.php?foo=bar")
43 * @result "data/test.php?foo=bar&10538358345554"
46 return value
+ (/\?/.test(value
) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math
.random()*100000);
50 // Store the old counts so that we only assert on tests that have actually leaked,
51 // instead of asserting every time a test has leaked sometime in the past
52 var oldCacheLength
= 0,
53 oldFragmentsLength
= 0,
58 * Ensures that tests have cleaned up properly after themselves. Should be passed as the
59 * teardown function on all modules' lifecycle object.
61 this.moduleTeardown = function () {
62 var i
, fragmentsLength
= 0, cacheLength
= 0;
64 // Allow QUnit.reset to clean up any attached elements before checking for leaks
67 for ( i
in jQuery
.cache
) {
71 jQuery
.fragments
= {};
73 for ( i
in jQuery
.fragments
) {
77 // Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test,
78 // if we unconditionally assert any of these, the test will fail with too many assertions :|
79 if ( cacheLength
!== oldCacheLength
) {
80 equals( cacheLength
, oldCacheLength
, "No unit tests leak memory in jQuery.cache" );
81 oldCacheLength
= cacheLength
;
83 if ( fragmentsLength
!== oldFragmentsLength
) {
84 equals( fragmentsLength
, oldFragmentsLength
, "No unit tests leak memory in jQuery.fragments" );
85 oldFragmentsLength
= fragmentsLength
;
87 if ( jQuery
.timers
.length
!== oldTimersLength
) {
88 equals( jQuery
.timers
.length
, oldTimersLength
, "No timers are still running" );
89 oldTimersLength
= jQuery
.timers
.length
;
91 if ( jQuery
.active
!== oldActive
) {
92 equals( jQuery
.active
, 0, "No AJAX requests are still active" );
93 oldActive
= jQuery
.active
;