Created
December 5, 2013 22:58
-
-
Save jlstr/7815560 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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