Skip to content

Instantly share code, notes, and snippets.

@grauwoelfchen
Last active December 21, 2015 09:19
Show Gist options
  • Save grauwoelfchen/6284515 to your computer and use it in GitHub Desktop.
Save grauwoelfchen/6284515 to your computer and use it in GitHub Desktop.
Test suite for JavaScript Ninja :-D
(function() {
var queue = [], paused = false, results;
this.test = function(name, fn) {
queue.push(function() {
results = document.getElementById("results");
results = assert(true, name).appendChild(
document.createElement("ul"));
fn();
});
runTest();
};
this.pause = function() {
paused = true;
};
this.resume = function() {
paused = false;
setTimeout(runTest, 1);
};
function runTest() {
if (!paused && queue.length) {
(queue.shift())();
if (!paused) {
resume();
}
}
}
this.assert = function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
if (!results) {
results = document.getElementById("results");
}
results.appendChild(li);
if (!value) {
li.parentNode.parentNode.className = "fail";
}
return li;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment