Skip to content

Instantly share code, notes, and snippets.

@vrotaru
Created Feb 2, 2016
Embed
What would you like to do?
<!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