-
-
Save raul/963499 to your computer and use it in GitHub Desktop.
quick'n'dirty javascript testing framework
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 lang=en> | |
<head> | |
<title>quick'n'dirty js testing framework</title> | |
<meta charset=utf-8> | |
<style type="text/css" media="screen"> | |
p { font: .8em courier; padding: .5em 1em; margin: 0;} | |
.pass { color: #4F8A10; background: #DFF2BF } | |
.fail { color: #D8000C; background: #FFBABA } | |
.error{ color: white; background: red } | |
</style> | |
<script> | |
function test(desc, fn) { | |
var output = function(klass, msg){ | |
document.write('<p class="' + klass + '">' + msg + '</p>') | |
} | |
var result | |
try{ result = fn() }catch(err){ result = err } | |
if (typeof result === 'boolean'){ | |
result ? output('pass', desc) : output('fail', desc) | |
}else{ | |
output('error', ['ERROR:',result.message,'when testing',desc].join(' ')) | |
} | |
} | |
/* usage: | |
function add(a, b) { return a+b; } | |
test("should add two integer numbers", function() { | |
return add(1, 2) == 3; | |
}); | |
*/ | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment