Skip to content

Instantly share code, notes, and snippets.

@akirchmyer
Created November 17, 2013 03:51
Show Gist options
  • Select an option

  • Save akirchmyer/7508872 to your computer and use it in GitHub Desktop.

Select an option

Save akirchmyer/7508872 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
<ul id="results"></ul>
(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, cb) {
results = document.getElementById('results');
results = assert(true, name).appendChild(
document.createElement('ul'));
cb();
};
}());
(function () {
console.log('we here');
test('A test - passes', function () {
assert(true, 'first assertion');
assert(true, 'second assertion');
assert(true, 'third assertion');
});
test('B test - failure', function () {
assert(true, 'first assertion');
assert(false, 'second assertion should fail');
assert(true, 'third assertion');
});
test('C test - oddities', function () {
assert(5, 'first assertion passes');
assert(null, 'second assertion fails');
});
}());
#results li.pass {
color: green;
}
#results li.fail {
color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment