1 function runTest(file) {
2 var startTime = new Date();
8 var fixture = document.getElementById('main').innerHTML;
9 $.get(file,function(js) {
10 js = js.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
12 var runTime = new Date() - startTime;
13 var result = document.createElement("div");
14 result.innerHTML = 'Tests completed in ' + runTime + ' milliseconds.<br/>' +
15 stats.bad + ' tests of ' + stats.all + ' failed.';
16 document.getElementsByTagName("body")[0].appendChild(result);
19 function test(name, callback) {
24 if(typeof console != "undefined") {
25 console.error("Test " + name + " died, exception and test follows");
27 console.warn(callback.toString());
29 Test.push( [ false, "Died on test #" + (Test.length+1) + ": " + e ] );
33 var good = 0, bad = 0;
34 var ol = document.createElement("ol");
36 var li = "", state = "pass";
37 for ( var i = 0; i < Test.length; i++ ) {
38 var li = document.createElement("li");
39 li.className = Test[i][0] ? "pass" : "fail";
40 li.innerHTML = Test[i][1];
51 var li = document.createElement("li");
54 var b = document.createElement("b");
55 b.innerHTML = name + " <b style='color:black;'>(<b class='fail'>" + bad + "</b>, <b class='pass'>" + good + "</b>, " + Test.length + ")</b>";
56 b.onclick = function(){
57 var n = this.nextSibling;
58 if ( jQuery.css( n, "display" ) == "none" )
59 n.style.display = "block";
61 n.style.display = "none";
66 document.getElementById("tests").appendChild( li );
70 document.getElementById('main').innerHTML = fixture;
75 * @example ok( $("a").size() > 5, "There must be at least 5 anchors" );
78 Test.push( [ !!a, msg ] );
82 * Asserts that two arrays are the same
84 function isSet(a, b, msg) {
86 if ( a && b && a.length == b.length ) {
92 if ( !ret && console )
93 console.log( msg, a, b );
94 Test.push( [ ret, msg ] );
98 * Returns an array of elements with the given IDs, eg.
99 * @example q("main", "foo", "bar")
100 * @result [<div id="main">, <span id="foo">, <input id="bar">]
104 for ( var i = 0; i < arguments.length; i++ )
105 r.push( document.getElementById( arguments[i] ) );
110 * Asserts that a select matches the given IDs
111 * @example t("Check for something", "//[a]", ["foo", "baar"]);
112 * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar'
115 var f = jQuery.find(b);
117 for ( var i = 0; i < f.length; i++ )
118 s += (s && ",") + '"' + f[i].id + '"';
119 isSet(f, q.apply(q,c), a + " (" + b + ")");