Created
August 3, 2011 18:47
-
-
Save taiansu/1123462 to your computer and use it in GitHub Desktop.
Javascript assert
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>JavaScript Testing Lab</title> | |
<style> | |
.pass:before { | |
content: 'PASS: '; | |
color: blue; | |
font-weight: bold; | |
} | |
.fail:before { | |
content: 'FAIL: '; | |
color: red; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<ul id="output"></ul> | |
<ul id="assertion"></ul> | |
<script> | |
var divAssertion = document.getElementById('assertion'); | |
function assert( outcome, description ) { | |
var li = document.createElement('li'); | |
li.className = outcome ? 'pass' : 'fail'; | |
li.appendChild( document.createTextNode( description ) ); | |
divAssertion.appendChild(li); | |
}; | |
var divOutput = document.getElementById('output'); | |
function writeln(result){ | |
var li = document.createElement('li'); | |
li.className = result ? 'pass' : 'fail'; | |
li.appendChild(document.createTextNode( result )); | |
divOutput.appendChild(li); | |
}; | |
</script> | |
<script type="text/javascript" charset="utf-8"> | |
//your can write javascript code here, and use assert function to test it. | |
//or use the block underneath to include your .js file form the same folder with this html file. | |
</script> | |
<script src=".js" type="text/javascript" charset="utf-8"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment