2012-06-14 10 views
8

मैं एक जावास्क्रिप्ट लाइब्रेरी बना रहा हूं और बीडीडी का उपयोग करना चाहता हूं, इसलिए मैं मोचा पर कोशिश कर रहा हूं और मैं इसे काम नहीं कर सकता। मैं क्लाइंट पर उस पुस्तकालय का उपयोग करना चाहता हूं, इसलिए मुझे लगता है कि यह एक ब्राउज करने योग्य यूआरएल से चलने के लिए समझ में आता है, वेब कनेक्शन के संदर्भ में होना चाहिए, न कि एक पथ से केवल एक सैंडबॉक्स।क्यों ब्राउज़र में मोचा ने यूआरएल से पता चला वैश्विक रिसाव फेंक दिया लेकिन एक पथ से नहीं?

यहाँ डमी प्रारंभिक बिंदु फ़ाइल परीक्षण है/

var assert = chai.assert; 

var foobar = { 
    sayHello: function() { 
    return 'Hello World!'; 
    } 
}; 

describe('Foobar', function() { 
    describe('#sayHello()', function() { 
     it('should work with assert', function() { 
     assert.equal(foobar.sayHello(), 'Hello World!'); 
    }); 

    }); 
}); 

test.foobar.js और यहाँ html पृष्ठ है कि परीक्षण को गति प्रदान है, test.html

<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Mocha Tests</title> 
    <link rel="stylesheet" href="testing/mocha.css" /> 
    <script src="testing/jquery.js"></script> 
    <script src="testing/mocha.js"></script> 
    <script>mocha.setup('bdd')</script> 
    <script src="testing/chai.js"></script> 
    <script src="test/test.foobar.js"></script> 
    <script> $(function() { mocha.run(); }) </script> 
</head> 
<body> 
    <div id="mocha"></div> 
</body> 
</html> 

जब मैं में खुला क्रोम या सफारी

file:///Users/me/dev/sandbox/test.html 

यह उम्मीद के रूप में, परीक्षण कोई त्रुटि

के साथ पारित काम करता है

जब मैं क्रोम या सफारी

http://localhost/sandbox/test.html 

में खोलने मैं निम्न त्रुटि और परीक्षण असफल हो

Error: global leak detected: script1339700707078 
    at Runner.checkGlobals (http://localhost/sandbox/testing/mocha.js:3139:21) 
    at Runner.<anonymous> (http://localhost/sandbox/testing/mocha.js:3054:44) 
    at Runner.emit (http://localhost/sandbox/testing/mocha.js:235:20) 
    at http://localhost/sandbox/testing/mocha.js:3360:14 
    at Test.run (http://localhost/sandbox/testing/mocha.js:3003:5) 
    at Runner.runTest (http://localhost/sandbox/testing/mocha.js:3305:10) 
    at http://localhost/sandbox/testing/mocha.js:3349:12 
    at next (http://localhost/sandbox/testing/mocha.js:3233:14) 
    at http://localhost/sandbox/testing/mocha.js:3242:7 
    at next (http://localhost/sandbox/testing/mocha.js:3192:23) 

कोई एक व्याख्या हो सकती है, और बेहतर एक समाधान?

उत्तर

0

मैं

<script> 
     onload = function(){ 
     var runner = mocha.run(); 
     }; 
</script> 

द्वारा

<script> $(function() { mocha.run(); }) </script> 

एक समाधान है कि सफारी में समस्या ठीक होती है ... की जगह मिला ... लेकिन अभी भी

+2

आप ऑनलोड एक के ऊपर एक स्क्रिप्ट टैग में निम्नलिखित जोड़ेंगे, तो वह क्रोम में इसे ठीक करना चाहिए (भी सामान्य रूप में उपयोगी वैश्विक): mocha.setup ({ui: 'BDD', वैश्विक : ['स्क्रिप्ट *']}) –

6
:-(क्रोम में त्रुटि मिलती है

यह mocha के साथ jQuery का उपयोग करने में एक मुद्दा था। JQuery वैश्विक वैरिएबल बनाता है जिसमें अद्वितीय आईडी है ... आपके मामले में script133...। हाल ही में मोचा 1.2 में रिलीज़ किया गया है आप वाई सेट कर सकते हैं ldcard ignores ...

$(function(){ 
    mocha 
    .globals([ 'script*' ]) // acceptable globals 
    .run(); 
}); 

सुनिश्चित करें कि आप अद्यतित हैं, और उचित रूप से कॉन्फ़िगर करें।

संदर्भ: Mocha 1.2.0 launch notice

संबंधित मुद्दे

 संबंधित मुद्दे