2012-09-20 18 views
8

का उपयोग कर जावास्क्रिप्ट निर्भरता इंजेक्शन मैं केवल RequJS और जैस्मीन का उपयोग करके मेरी यूनिट परीक्षण रणनीति में निर्भरता इंजेक्शन की तलाश कर रहा हूं। मुझे वास्तव में testr के पीछे विचार पसंद है और मैंने जिथब में उदाहरणों के बाद टेस्टर सेट अप करने का प्रयास किया है, लेकिन मैं यह नहीं समझ सकता कि क्या गलत है। मुझे हमेशा त्रुटिRequjS, जैस्मीन और testr

Error: module has not been loaded: today

जब परीक्षक परीक्षण किए जाने वाले मॉड्यूल को लोड करने का प्रयास करता है।

यहाँ कुछ संदर्भ ..

index.html ..

<script data-main="config" src="../../assets/js/libs/require.js"></script> 
<script src="vendor/testr.js"></script> 

config.js ..

require.config({ 

    // Initialize specs. 
    deps:["main"], 
... 
... 
}); 

main.js ..

require([ 
    // Load the example spec, replace this and add your own spec 
    "spec/today" 
], function() { 
    var jasmineEnv = jasmine.getEnv(); 
    jasmineEnv.execute(); 
}); 

कल्पना \ ..

describe('Today print', function() { 
    var date = {}, today; 
    beforeEach(function() { 
    date.today = new Date(2012, 3, 30); 
    today = testr('today', {'util/date': date}); //Here is where the error is thrown 
    }); 

    it('is user-friendly', function() { 
    expect(today.getDateString()).toBe('Today is Monday, 30th April, 2012'); 
    }); 
}); 

today.js today.js ..

define(['string', 'util/date'], function(string, date) { 
    return { 
    getDateString: function() { 
     return string.format('Today is %d', date.today); 
    } 
    } 
}); 

वहाँ किसी को भी उस के साथ किया गया है है एक ही तरह की परेशानी? । मैं RequJS 2.0.6

धन्यवाद का उपयोग कर रहा हूं।

उत्तर

1

आपके 'आज' मॉड्यूल को testr के साथ उपयोग करने से पहले requjs से लोड करने की आवश्यकता है।

require(['today'], function(){ 
    describe('Today print', function() { 
     var date = {}, today; 
     beforeEach(function() { 
     date.today = new Date(2012, 3, 30); 
     today = testr('today', {'util/date': date}); //Here is where the error is thrown 
     }); 

     it('is user-friendly', function() { 
     expect(today.getDateString()).toBe('Today is Monday, 30th April, 2012'); 
     }); 
    }); 
}); 

भी पढ़ें:: http://cyberasylum.janithw.com/mocking-requirejs-dependencies-for-unit-testing/

+0

ठीक की तरह कुछ की कोशिश करो। मैं अभी कुछ दिनों के लिए टेस्टर काम करने के लिए काम कर रहा हूं। यह एक निकटतम परियोजना है जो मैं एक उदाहरण परियोजना देखने के लिए आया हूँ। मैंने दूसरों के साथ साझा करने के लिए जैस्मीन का उपयोग करके इस उदाहरण (कुछ मामूली tweaks के साथ) के लिए एक github रेपो बनाया है। हालांकि, यह अभी भी काम नहीं कर रहा है। क्या कोई यहां मदद कर सकता है? धन्यवाद। https://github.com/loesak/jasmine-maven-require-testr – loesak

+0

मुझे एक ही समस्या है। असल में, मैं मैन्युअल रूप से इसे मेरी ज़रूरतों में एक डिप्टी के रूप में लोड करता हूं, और कर्म दिखाता है कि फ़ाइल अनुरोध कर रही है (पहले)। – FlavorScape