Last active
December 17, 2015 23:19
-
-
Save astockwell/5688788 to your computer and use it in GitHub Desktop.
Simple JS Assert Unit Testing function (via http://net.tutsplus.com/tutorials/javascript-ajax/quick-tip-quick-and-easy-javascript-testing-with-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
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); | |
}; | |
// Useage: | |
function add(num1, num2) { | |
return num1 + num2; | |
} | |
var result = add(5, 20); | |
assert( result == 24, 'Checking the add function'); | |
// OR | |
assert( add( 5, 20 ) == 24, 'Checking the add function'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment