About jsUnity
What is it?
jsUnity is a lightweight, environment-agnostic JavaScript testing framework: It doesn’t rely on any browser capabilities and therefore can be used in any client-side or server-side JavaScript environment.
Why jsUnity?
There are already several unit testing frameworks for JavaScript that are browser-centric. jsUnity aims to just focus on JavaScript as a language that’s used beyond the browser context.
In a nutshell…
The most concise way of running a test suite with jsUnity:
var results = jsUnity.run(function () {
function testSomething() {
jsUnity.assertions.assertTrue(someFlag);
}
});
Alternative ways for defining test suites:
function testSuite1() {
function testSomething1() {}
}
var testSuite2 = {
suiteName: "testSuite2",
testSomething2: function () {}
}
function testSomething3() {}
var testSuite3_1 = [ testSomething3 ];
var testSuite3_2 = [ "testSomething3" ];
var testSuite4 = "function testSomething4() {}";
jsUnity.log = function (s) {
document.write("<div>" + s + "</div>");
};
jsUnity.run(testSuite1, testSuite2,
testSuite3_1, testSuite3_2, testSuite4);
Here’s the output you’d get from the above:
Running testSuite1
1 test found
[PASSED] testSomething1
Running testSuite2
1 test found
[PASSED] testSomething2
Running unnamed test suite
1 test found
[PASSED] testSomething3
Running unnamed test suite
1 test found
[PASSED] testSomething3
Running unnamed test suite
1 test found
[PASSED] testSomething4
5 tests passed
0 tests failed
16 milliseconds elapsed
Head over to the tutorial or the reference for all the details.