Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Last active June 12, 2022 11:00
Show Gist options
  • Save remarkablemark/04cb6bc9332bef3daace857520ad3608 to your computer and use it in GitHub Desktop.
Save remarkablemark/04cb6bc9332bef3daace857520ad3608 to your computer and use it in GitHub Desktop.
Example of mocha in the browser.
<!DOCTYPE html>
<html>
<head>
<!-- styling for the test results -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.1.0/mocha.min.css" />
</head>
<body>
<!-- container that will display test results -->
<div id="mocha"></div>
<!-- mocha (test runner) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mocha/3.1.0/mocha.min.js"></script>
<!-- chai (assertion library) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.min.js"></script>
<script>
// setup test helpers
mocha.setup('bdd');
// your tests here
describe('test suite', function() {
it('should work', function() {
chai.assert(true);
});
});
// run tests
mocha.run();
</script>
</body>
</html>
@remarkablemark
Copy link
Author

You can also install mocha and chai locally:

$ npm install mocha chai

You'll also need to update the script source.

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