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.
Written by Kotrotsos
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#