Using modules can make it easy to globally configure / disable your test suite. The following is an example of using RequireJS (AMD modules):
First, let's define a test environment with our global install / disable:
// test-env.js define('test-env', [], function() { // One can store globals, which will be available within the // whole test suite. var my_global = true; before(function() { // global setup }); return after(function() { // global teardown }); });
In our JS runner (included in the HTML mocha runner, for other libraries and test files, like <script type="text/javascript">…</script> or better, as an external JS file):
require([ // this is the important thing: require the test-env dependency first 'test-env', // then, require the specs 'some-test-file' ], function() { mocha.run(); });
some-test-file.js can be implemented as follows:
// some-test-file.js define(['unit-under-test'], function(UnitUnderTest) { return describe('Some unit under test', function() { before(function() { // locally "global" setup }); beforeEach(function() { }); afterEach(function() { }); after(function() { // locally "global" teardown }); it('exists', function() { // let specify the unit under test }); }); });
chikamichi Jul 04 2018-11-14T00: 00Z
source share