Javascript - Test Framework

1 - About

Test - Unit Test Framework (xUnit) in Javascript

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

3 - 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.");

4 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap