Last active
August 29, 2015 14:13
-
-
Save dasibre/710d8265bf7013a150af to your computer and use it in GitHub Desktop.
javascript custom test suite
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
<script type="text/javascript"> | |
(function foo() { | |
this.buzz = function buzz() { | |
return 'buzz'; | |
} | |
console.log('I am a self invoking function'); | |
})(); | |
(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(); | |
}; | |
})(); //iffy self executing function | |
window.onload = function() { | |
test("A test. ", function testA() { | |
assert(true, "First assertion completed"); | |
assert(true, "Second assertion completed"); | |
assert(true, "Third assertion completed"); | |
}); | |
test("Another test.", function testB() { | |
assert(true, "first test completed"); | |
assert(false, "second test failed"); | |
assert(true, "Third assertion completed"); | |
}); | |
test("A third test", function testC() { | |
assert(null, "fail"); | |
assert(5, "pass"); | |
}); | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment