Tracing/logging
A common problem when debugging JavaScript is that it is harder in JavaScript than in most languages to print out simple trace statements. Commonly, the developer has to resort to using the "alert()" function. While it does work well, it can be frustrating as you progress in tracking down a problem to step past many alert statements to get to your latest one. Also, the developer typically has to go back and remove each alert when (s)he is finished debugging, which takes time, and is especially annoying if another similar problem has to be tracked down later where the original alert calls would have been useful. Finally, using alerts can alter the behavior of the code, especially when UI events are occurring.
JsUnit supports tracing. There are 3 tracing levels - warn, info, and debug. When running tests, you can specify which level of tracing you want (see "Running Tests"). The levels cascade in the order warn->info->debug. That is, if you choose "warn" as your tracing level, you will see only warn traces. If you choose "info", you will see all warn and info traces. If you choose "debug", you will see all traces. (You can also choose "No tracing", which is the default.)
There are three functions that you can call anywhere in your tests:
function warn(message, [value]) function inform(message, [value]) (equivalent to function info(message, [value])) function debug(message, [value])
In each case the value parameter is optional. For example, if x were 7, the code
warn("Variable x should never be greater than 5", x);
would result in the trace "Variable x should never be greater than 5: 7". See the Test Page "jsUnitFrameworkUtilityTests.html" which comes with JsUnit for more examples.