Last active
January 19, 2021 12:23
-
-
Save wardbell/9ead31db1ce8ccdaf387 to your computer and use it in GitHub Desktop.
Minimal mocha/chai in browser
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
<!DOCTYPE html> | |
<html> | |
<head lang="en"> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" /> | |
<title>Mocha/Chai Basic Tests</title> | |
<style> | |
body { | |
font: 18px/1.5 "Helvetica Neue", Helvetica, sans-serif; | |
padding-left: 20px; | |
} | |
</style> | |
</head> | |
<body> | |
<p> | |
Click <a href="/minMocha.html" title="Start over"><img src="https://raw.githubusercontent.com/johnpapa/pluralsight-ng-testing/master/src/client/images/home.png" style="width: 18px"></a> to start over.<br/> | |
Click a <em>description title</em> to run its specs only | |
(see "<a href="http://mochajs.github.io/mocha/#grep-option" target="_blank" title="MochaJS grep option"> | |
?grep</a>" in address bar).<br/> | |
Click a <em>spec title</em> to see its implementation. | |
</p> | |
<div id="mocha"></div> | |
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.css" /> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/chai/1.10.0/chai.min.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/mocha/2.1.0/mocha.min.js"></script> | |
<script src="//cdn.rawgit.com/rstacruz/mocha-clean/v0.3.0/index.js"></script> | |
<script> | |
mocha.setup('bdd'); | |
mocha.traceIgnores = ['mocha.min.js', 'chai.min.js']; | |
expect = chai.expect; | |
</script> | |
<script> | |
<!-- specs/tests here --> | |
</script> | |
<script> | |
mocha.run(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minimal mocha/chai in browser
Demonstrates my idea of the "minimum, effective" example of mocha/chai that can be run in a browser.
Try it
Serve it in brackets.io
Serve it w/ node "live-server"
The brackets "live preview" is nice but (a) you might not be using brackets and (b) is has a significant annoyance: it disconnects when you open the chrome developer tools.
You might find using the node-based "live-server" is a more robust solution that also works with other editors and IDEs.
npm install live-server -g
live-server
What's up in the HTML?
Load one css & three scripts (from a cdn where possible)
Add "Home" icon with anchor to reset the page to its base state
Add mocha div to hold test runner output
Add script to configure mocha/chai
Add script with sample tests
Launch the mocha testrunner