From f8b7d391e6baa991dd7f8761ee50871aefef71b8 Mon Sep 17 00:00:00 2001 From: John Resig Date: Tue, 29 Sep 2009 18:11:10 +0000 Subject: [PATCH] Moved some jQuery-specific test methods into the core module. --- test/data/testinit.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/data/testinit.js b/test/data/testinit.js index 41aa396..94d18f3 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -2,3 +2,46 @@ var jQuery = this.jQuery || "jQuery", // For testing .noConflict() $ = this.$ || "$", originaljQuery = jQuery, original$ = $; + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [
, , ] + */ +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) { + var f = jQuery(b), s = ""; + + for ( var i = 0; i < f.length; i++ ) { + s += (s && ",") + '"' + f[i].id + '"'; + } + + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +/** + * 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); +} -- 1.7.10.4