Skip to content

Instantly share code, notes, and snippets.

@raul
Forked from javisantana/test.js
Created May 9, 2011 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save raul/963499 to your computer and use it in GitHub Desktop.
Save raul/963499 to your computer and use it in GitHub Desktop.
quick'n'dirty javascript testing framework
<!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