Table of Contents

About

Test - Unit Test Framework (xUnit) in Javascript

A test framework is composed of two part that you can use separately:

Implementation Example

  • The function to test named plus1
function plus1(a){
    return a + 1;
}
  • The test function of the plus1 function
function test(then, expected) {
    results.total++;
    var result = plus1(then);
    if (result !== expected) {
        results.bad++;
        console.log("Expected " + expected + ", but was " + result);
    }
}
  • The run
var results = {
    total: 0,
    bad: 0
};
test(1, 2);
test(2, 4);
  • The result
console.log("Of " + results.total + " tests, " + results.bad + " failed, " +  (results.total - results.bad) + " passed.");

List

Documentation / Reference