मॉड्यूल का उपयोग वैश्विक सेटअप/टियरडाउन के लिए आसान बना सकता है आपका परीक्षण सूट यहाँ RequireJS का उपयोग कर एक उदाहरण (एएमडी मॉड्यूल) है:
पहले, आइए हमारे वैश्विक सेटअप/टियरडाउन के साथ एक परीक्षण पर्यावरण को परिभाषित करते हैं:
// 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
});
});
हमारे जे एस धावक में (मोचा के एचटीएमएल धावक में शामिल है, अन्य के साथ libs और परीक्षण फ़ाइलें, एक <script type="text/javascript">…</script>
, या बेहतर, एक बाहरी जे एस फ़ाइल के रूप में) के रूप में:
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