Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Created February 2, 2016 17:53
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 vrotaru/70dac4740a4281a0a9c8 to your computer and use it in GitHub Desktop.
Save vrotaru/70dac4740a4281a0a9c8 to your computer and use it in GitHub Desktop.
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Easy JavaScript Testing></title>
<style>
.pass:before {
content: 'PASS: ';
color: blue;
font-weight: bold;
font-family: monospace
}
.fail:before {
content: 'FAIL: ';
color: red;
font-weight: bold;
font-family: monospace
}
</style>
</head>
<body>
<ul id="output"></ul>
<script>
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);
};
function add(num1, num2) {
return num1 + num2;
}
assert (add(5, 20) === 24, '5 + 20 = 24')
assert (add(5, 20) === 25, '5 + 20 = 24')
</script>
</body>
<html>
@vrotaru
Copy link
Author

vrotaru commented Feb 2, 2016

As seen here Quick and Easy JavaScript testing with assert with one minor change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment