MICRO-API for test harness The tests are in DOMtests: var DOMtests = [ { // test 1 }, { // test 2 }, // etc. ]; These tests are done in the order specified here. That sometimes matters. There are two complicated cases: user questions and asynchronous tests: - User questions are asked after all the tests have been done. This may matter if the element the question is about is changed in a subsequent test. - Async tests are done after a delay specified in the test. This is sometimes necessary (XHR, for instance), and at other times it's useful to give the browser some time to adjust the DOM tree. Each individual test can have the following properties: output string The header under which the result is shown (generated automatically) outputtext string The text shown with the result. If absent it's the same as output. test function The actual test function. Should return a value that can be compared to an expected value. expectedValue string; possibly HTML The value the test function is expected to return. If the function returns another value, the test is Wrong. caseInsensitive true The expected value and returned value are forced to lower case and then compared. checkReturnValue true Indicates this test should return a truey value. The test succeeds if it does. shouldNotWork true Indicates that this test should give an error. It essentially reverses the test result: true to false and false to true description string A descriptive text to be shown with the test results. Has no bearing on the actual test. optional true Indicates this question does not count for the final result. Used mainly for vendor prefixes. question object Defines a user question. See below. async object Defines an async test. See below. The following properties are generated by the test harness result 'worked', 'error', 'undefined', 'wrong' The result of the test. 'worked' means the test succeeded 'wrong' means the test returned a wrong value 'undefined' means the test returned the undefined value 'error' means the test threw an error returnValue any The value returned by the test function. Is usually compared to expectedValue. USER QUESTIONS You can add a question object to a test, and the user will be asked a question. A Yes is interpreted as a succeeded test; a No as a failed test. (Using shouldNotWork reverses this.) Each question object can have the following properties questionText string The text the user sees and is asked to answer by Yes or No. fn function A function that runs just prior to the question being asked. It should receive testArea as an argument; this is the area where you can show an HTML snippet to the user. fnAfter function A function that runs after the user has answered the question. Useful for cleaning up. Note that first all main tests run, and the user questions come only afterwards, in order of the main test objects. This may matter if you run several tests with the same HTML test element. The following property is generated by the test harness: result any The result (returned value) of the main test. This is useful for returning an object that should be shown to the user; for instance: test: function(id) { // test something this.question.result = document.getElementById('theTestElement'); } ... and then ... fn: function(testArea) { testArea.appendChild(this.result); } ASYNC Some tests require asynchronicity. To label a test asynchronous, make sure to set an async object on the main test object. This alerts the test harness to an upcoming asynchronous test. async is an object that can contain the following properties: ignoreMain true Indicates that the main test function should not be reported. Only the asynchronous test counts here. If you do not set this property the main test and the asynchronous test will be treated as two separate tests. any test property You can repeat any property of the main test object in an async object. The new value will be used for the asynchronous test; the old one will be used for the main test and discarded afterwards. The asynchronous test function MUST go inside a special async() function call at its normal place in your test script. The harness needs this function to run for administrative purposes. async(test ID,test function); For instance, this function tests the readyState property of XHR: test: function (id) { var x = new XMLHttpRequest(); x.open('POST','test.txt'); x.onreadystatechange = function () { async(id,function() { return x.readyState; }); }; x.send(); } Note the id arguments in the main function and async(). They're required; they make sure the asynchronous test result is properly reported.