Skip to content

Instantly share code, notes, and snippets.

@jlstr
Created December 5, 2013 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlstr/7815560 to your computer and use it in GitHub Desktop.
Save jlstr/7815560 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Ninja Template</title>
<style>
body { background: #d6d6d6; }
#results li.pass { color: green; }
#results li.fail { color: red; }
</style>
</head>
<body>
<h2>Test Groups</h2>
<script>
(function() {
//var results;
this.assert = function assert(value, desc) {
var li = document.createElement("li");
li.className = value ? "pass" : "fail";
li.appendChild(document.createTextNode(desc));
results.appendChild(li);
if(!value) {
li.parentNode.parentNode.className = "fail";
}
console.log(li);
return li;
}
this.test = function test(name, fn) {
results = document.getElementById("results");
results = assert(true, name).appendChild(
document.createElement("ul"));
fn();
}
})();
window.onload = function() {
test("Test Group #1", function() {
assert(true, "First assertion completed");
assert(true, "Second assertion completed");
});
test("Test Group #2", function() {
assert(true, "Third assertion completed");
assert(false, "Fourth assertion completed");
});
}
</script>
<ul id="results"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment