Skip to content

Instantly share code, notes, and snippets.

@lyuehh
Created April 9, 2013 12:16
Show Gist options
  • Save lyuehh/5345235 to your computer and use it in GitHub Desktop.
Save lyuehh/5345235 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Assert Test Suite</title>
<script type="text/javascript">
(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';
}
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('A test', function() {
assert(true, "First completed");
assert(true, "Second completed");
assert(true, "Third completed");
});
test('Another test', function() {
assert(true, "First completed");
assert(false, "Second failed");
assert(true, "First completed");
});
test('A third test.', function() {
assert(null, 'fail');
assert(5, 'pass');
assert();
});
};
</script>
<style type="text/css">
#results li.pass {color: green;}
#results li.fail {color: red;}
</style>
</head>
<body>
<ul id="results"></ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment