JSFiddle - React, Tailwind, and code Playground
HTML
<div id="output"></div>
JavaScript
(function () {
// A simple JavaScript test framework.
//
// > Your app is complex. Testing it should be simple. --Isaac Newton
//
// - http://en.wikipedia.org/wiki/Occam's_razor
// - http://en.wikipedia.org/wiki/Worse_is_better
// - http://en.wikipedia.org/wiki/KISS_principle
// - http://en.wikipedia.org/wiki/Unix_philosophy
var suite, test, assert, defaultPrinter;
defaultPrinter = function () {
console.log(this.passed, this.name);
};
suite = function (description, callback, printer) {
var context = { name: [description] };
context.printer = printer || defaultPrinter;
callback.call(context);
};
assert = function (self, description, value) {
self.printer.call({
name: self.name.concat([description]),
passed: !!value
});
};
test = function (self, description, callback) {
var context = { printer: self.printer };
context.name = self.name.concat([description]);
callback.call(context);
};
// Usage Example
// want to change the printed output?
var htmlPrinter = function () {
var status = this.passed ? "PASS" : "FAIL";
var message = status + ": " + this.name.join(" ");
document.getElementById("output").innerHTML += message + "<br>";
};
suite("contrived example", function () {
test(this, "auto", function () {
test(this, "car", function () {
assert(this, "has engine", true);
assert(this, "has 4 wheels", true);
assert(this, "can accelerate", true);
assert(this, "can stop", true);
test(this, "yugo", function () {
// async example
var yugo = this;
setTimeout(function () {
assert(yugo, "is slow", true);
}, 1000);
assert(this, "is crappy", true);
});
test(this, "mustang", function () {
assert(this, "is fast", true);
assert(this, "is fun", true);
});
});
test(this, "truck", function () {
...