Rework unit tests to check actual result elements.
[jquery.git] / test / data / testinit.js
1 var jQuery = this.jQuery || "jQuery", // For testing .noConflict()
2         $ = this.$ || "$",
3         originaljQuery = jQuery,
4         original$ = $,
5         commonJSDefined;
6
7 function define(module, dependencies, callback) {
8         commonJSDefined = callback();
9 }
10
11 /**
12  * Returns an array of elements with the given IDs, eg.
13  * @example q("main", "foo", "bar")
14  * @result [<div id="main">, <span id="foo">, <input id="bar">]
15  */
16 function q() {
17         var r = [];
18
19         for ( var i = 0; i < arguments.length; i++ ) {
20                 r.push( document.getElementById( arguments[i] ) );
21         }
22
23         return r;
24 }
25
26 /**
27  * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]);
28  * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baa
29 r'
30  */
31 function t(a,b,c) {
32         var f = jQuery(b).get(), s = "";
33
34         for ( var i = 0; i < f.length; i++ ) {
35                 s += (s && ",") + '"' + f[i].id + '"';
36         }
37
38         same(f, q.apply(q,c), a + " (" + b + ")");
39 }
40
41 /**
42  * Add random number to url to stop IE from caching
43  *
44  * @example url("data/test.html")
45  * @result "data/test.html?10538358428943"
46  *
47  * @example url("data/test.php?foo=bar")
48  * @result "data/test.php?foo=bar&10538358345554"
49  */
50 function url(value) {
51         return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000);
52 }