Modüllerin kullanımı, global bir kurulum/göz atma işlemini daha kolay hale getirebilir Test takımın. İşte RequireJS kullanarak bir örnek (AMD modülleri) 'dir:
Öncelikle global kurulum/devrelerde bir test ortamı tanımlayalım: Bizim JS koşucu olarak
// 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
});
});
(diğer boyunca, mocha HTML koşucu dahil libs ve test dosyaları, bir <script type="text/javascript">…</script>
, ya da daha iyi, gibi harici JS dosyası):
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
böyle uygulanabilir:
// 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
});
});
});
Biraz açıklayabilir misiniz, orada neler oluyor? – Gobliins