Created
January 18, 2020 02:11
-
-
Save scottmwyant/843b489b93ac8e2bc7161e0d0c53a09a to your computer and use it in GitHub Desktop.
Mocha Testing in the Browser with ES6
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 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> |
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
export default function (name) { | |
return "Hello, " + name; | |
} |
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
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