I'm looking for a JavaScript Testing Framework that I can easily use in whatever context, be it browser, console, XUL, etc.
Is there such a framework, or a way to easily retrofit an existing framework so its context agnostic?
Edit: The testing framework should not be tied to any other framework such as jQuery or Prototype.js and shouldn't depend on a DOM (or document object) being present. I'm looking for something to test pure JavaScript.
OK, here's something I just brewed based on some earlier work. I hope this would meet your needs.
Lightweight Universal JavaScript Testing Framework
jsUnity is a lightweight universal JavaScript testing framework that is context-agnostic. It doesn't rely on any browser capabilities and therefore can be run inside HTML, ASP, WSH or any other context that uses JavaScript/JScript/ECMAScript.
<pre>
<script type="text/javascript" src="../jsunity.js"></script>
<script type="text/javascript">
function sampleTestSuite() {
    function setUp() {
        jsUnity.log("set up");
    }
    function tearDown() {
        jsUnity.log("tear down");
    }
    function testLessThan() {
        assertTrue(1 < 2);
    }
    function testPi() {
        assertEquals(Math.PI, 22 / 7);
    }
}
// optionally wire the log function to write to the context
jsUnity.log = function (s) { document.write(s + "</br>"); };
var results = jsUnity.run(sampleTestSuite);
// if result is not false,
// access results.total, results.passed, results.failed
</script>
</pre>
The output of the above:
2 tests found set up tear down [PASSED] testLessThan set up tear down [FAILED] testPi: Actual value does not match what's expected: [expected] 3.141592653589793, [actual] 3.142857142857143 1 tests passed 1 tests failed
Jasmine looks interesting.
According to the developers, it was written because none of the other JS test frameworks met all their needs in a single offering and not requiring things like DOM, jQuery, or the window object is one of the explicit design points.
I'm thinking of using it with env.js and Rhino/SpiderMonkey/V8/etc. to write client-side tests for my web apps which can be easily run in all the same situations as Python unit tests. (setup.py test, BuildBot, etc.)
you might want to check out YUI Test. It should work fine without a DOM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With