Использование модулей может облегчить глобальную настройку/отключение для ваш тестовый набор. Ниже приведен пример использования RequireJS (модули AMD):
Во-первых, давайте определим тестовую среду с нашей глобальной установки/демонтажа:
// 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
});
});
В нашем JS бегуна (входит в мокко HTML-бегуна, а другой ЛИЭС и тестовые файлы, как <script type="text/javascript">…</script>
, или лучше, как внешний файл JS):
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
могут быть реализованы следующим образом:
// 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's specify the unit under test
});
});
});
вы можете немного объяснить, что там происходит? – Gobliins