Assert function
Resig's assert function for testing javascript with example
by jorgeluis
HTML
<h1>Test Results</h1>
<ul id="output"></ul>
CSS
.pass:before {
content: 'PASS: ';
color: blue;
font-weight: bold;
}
.fail:before {
content: 'FAIL: ';
color: red;
font-weight: bold;
}
JavaScript
var output = document.getElementById('output');
function assert( outcome, description ) {
var li = document.createElement('li');
li.className = outcome ? 'pass' : 'fail';
li.appendChild( document.createTextNode( description ) );
output.appendChild(li);
};
/* TESTS */
function add(num1, num2) {
return num1 + num2;
}
assert( add( 4, 20 ) == 24, 'Checking the add function');