Skip to content

Instantly share code, notes, and snippets.

@scottmwyant
Created January 18, 2020 02:11
Show Gist options
  • Save scottmwyant/843b489b93ac8e2bc7161e0d0c53a09a to your computer and use it in GitHub Desktop.
Save scottmwyant/843b489b93ac8e2bc7161e0d0c53a09a to your computer and use it in GitHub Desktop.
Mocha Testing in the Browser with ES6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link href="https://unpkg.com/mocha@7.0.0/mocha.css" rel="stylesheet" />
<script src="https://unpkg.com/chai@4.2.0/chai.js"></script>
<script src="https://unpkg.com/mocha@7.0.0/mocha.js"></script>
<script type="module" src="test.js"></script>
</head>
<body style="padding: 30px;">
<h1>Mocha Tests</h1>
<div id="mocha"></div>
</body>
</html>
export default function (name) {
return "Hello, " + name;
}
import greeting from './module.js';
function defineTests() {
describe('sum', function () {
it('should return sum of arguments', function () {
chai.assert.equal(greeting('Scott'), 'Hello, Scott');
});
});
}
// ===============================================
// R U N T E S T S
// ===============================================
(function () {
function setup() {
mocha.setup('bdd')
};
function define() {
}
function run() {
mocha.checkLeaks();
mocha.run();
}
setup();
defineTests();
run();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment