8 function runTest(tests) {
9 var startTime = new Date();
11 fixture = document.getElementById('main').innerHTML;
13 var runTime = new Date() - startTime;
14 var result = document.createElement("div");
15 result.innerHTML = 'Tests completed in ' + runTime + ' milliseconds.<br/>' +
16 stats.bad + ' tests of ' + stats.all + ' failed.';
17 document.getElementsByTagName("body")[0].appendChild(result);
20 function test(name, callback) {
25 if(typeof console != "undefined") {
26 console.error("Test " + name + " died, exception and test follows");
28 console.warn(callback.toString());
30 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
34 var good = 0, bad = 0;
35 var ol = document.createElement("ol");
37 var li = "", state = "pass";
38 for ( var i = 0; i < Test.length; i++ ) {
39 var li = document.createElement("li");
40 li.className = Test[i][0] ? "pass" : "fail";
41 li.innerHTML = Test[i][1];
52 var li = document.createElement("li");
55 var b = document.createElement("b");
56 b.innerHTML = name + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
57 b.onclick = function(){
58 var n = this.nextSibling;
59 if ( jQuery.css( n, "display" ) == "none" )
60 n.style.display = "block";
62 n.style.display = "none";
67 document.getElementById("tests").appendChild( li );
71 * Resets the test setup. Useful for tests that modify the DOM.
74 document.getElementById('main').innerHTML = fixture;
79 * @example ok( $("a").size() > 5, "There must be at least 5 anchors" );
82 Test.push( [ !!a, msg ] );
86 * Asserts that two arrays are the same
88 function isSet(a, b, msg) {
90 if ( a && b && a.length == b.length ) {
96 if ( !ret && console )
97 console.log( msg, a, b );
98 Test.push( [ ret, msg ] );
102 * Returns an array of elements with the given IDs, eg.
103 * @example q("main", "foo", "bar")
104 * @result [<div id="main">, <span id="foo">, <input id="bar">]
108 for ( var i = 0; i < arguments.length; i++ )
109 r.push( document.getElementById( arguments[i] ) );
114 * Asserts that a select matches the given IDs
115 * @example t("Check for something", "//[a]", ["foo", "baar"]);
116 * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
119 var f = jQuery.find(b);
121 for ( var i = 0; i < f.length; i++ )
122 s += (s && ",") + '"' + f[i].id + '"';
123 isSet(f, q.apply(q,c), a + " (" + b + ")");