Created
January 16, 2014 18:45
-
-
Save prakhar1989/8460886 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
<meta charset=utf-8 /> | |
<title>Test Suite!</title> | |
<style> | |
li.pass { background: green; | |
color: white;} | |
li.fail { background: red; color: white;} | |
ul#results ul { margin-bottom: 10px;} | |
</style> | |
</head> | |
<body> | |
<ul id="results"></ul> | |
</body> | |
</html> |
This file contains hidden or 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
// test library | |
(function() { | |
var results; | |
this.assert = function(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"; | |
} | |
return li; | |
}; | |
this.test = function(title, testCases) { | |
results = document.getElementById('results'); | |
// logging the test name as TRUE | |
results = assert(true, title).appendChild( | |
document.createElement('ul')); | |
testCases(); | |
}; | |
})(); | |
// testing functions | |
function sqr(n) { return n * n ; } | |
// bootstraper | |
window.onload = function() { | |
test("A test", function() { | |
assert(true, "assert is passing"); | |
assert(false, "assert is failing"); | |
assert(5 === 5, "simple shit"); | |
}); | |
test("my lib", function() { | |
assert(true, "passing"); | |
assert(43 === 40 + 3, "addition"); | |
assert(4 == sqr(2), "squaring"); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment