Skip to content

Instantly share code, notes, and snippets.

@shanimal
Forked from calvinf/js-testing-playground.html
Created November 18, 2016 16:20
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 shanimal/92367dfde11c7359db6e0be69f45374a to your computer and use it in GitHub Desktop.
Save shanimal/92367dfde11c7359db6e0be69f45374a to your computer and use it in GitHub Desktop.
JavaScript Testing Playground (Mocha, Chai, and $script)
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript Testing Playground</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.min.css" rel="stylesheet" />
<style>
*, *:before, *:after {
box-sizing: border-box;
}
body {
font-family: Helvetica Neueu, Arial, sans-serif;
}
header, footer {
margin: 20px;
}
header h1 {
font-weight: normal;
}
.results-container{
margin: 0 auto;
max-width: 1200px;
width: 80%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/script.js/2.5.7/script.min.js"></script>
<script>
$script([
'https://cdnjs.cloudflare.com/ajax/libs/chai/3.0.0/chai.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.min.js'
], 'app');
</script>
</head>
<body>
<header><h1>JavaScript test bed</h1></header>
<div class="results-container">
<div id="mocha"></div>
</div>
<footer>
via <a href="http://calvinf.com/">Calvin Freitas</a>
</footer>
<script>
(function(window){
// test JavaScript goes here
})(window);
(function(window) {
$script.ready('app', function() {
var mocha = window.mocha;
mocha.setup('tdd');
var chai = window.chai;
chai.config.includeStack = true;
var assert = chai.assert;
suite('name of test suite', function(){
test('name of test', function() {
assert.isTrue(true);
assert.isFalse(false);
});
});
mocha.run();
})
})(window);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment