Last Updated: September 09, 2019
·
455
· kotrotsos

Really easy JS testing

QUnit or Jasmine way to fat for your tests? How about this easy to use and digest assert function?

function assert(pass, msg){
    var result = pass ? "PASS" : "FAIL";
    console.log(result + ":",msg);
}

Usage:

// Gonna pass- no matter what
assert(true,"This just has to pass");

// Should fail
var a = 1;
assert(a === 2, "Value of one");

You can dress up the result any which way you like. For instance I am presenting results in console, but there is no way stopping you for outputting to a result list in HTML.

$(".result").append("<li class='" + result + "'><strong>" + result + "</strong> " + msg + "</li>");

Thanks to John Resig for inspiration.