Skip to content

Instantly share code, notes, and snippets.

@taiansu
Created August 3, 2011 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taiansu/1123462 to your computer and use it in GitHub Desktop.
Save taiansu/1123462 to your computer and use it in GitHub Desktop.
Javascript assert
<!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