2015-01-21 6 views
5

एकीकृत क्विनेट परीक्षण फ़्रेमवर्क का उपयोग करके मुझे गीलेर का परीक्षण करने की आवश्यकता है या किसी रूट पर जाने की आवश्यकता नहीं है क्योंकि त्रुटि को फेंक दिया जाता है।Ember.js में त्रुटियों को फेंकने के लिए टेस्ट

मार्ग में एक हैंडलबार सहायक है जो कुछ शर्तों (असफल असफलता) के तहत त्रुटि फेंकना चाहिए। मैं गीला परीक्षण कैसे करूं या नहीं, यह त्रुटि फेंक दी गई है?

यह मैं अब तक क्या मिला है:

test('throws, if the SVG is missing', function() { 
    throws(visit('/missing'), Error, "has thrown an Error"); 
}); 

लेकिन यह काम नहीं करता है, के रूप में त्रुटि throws(...) द्वारा पकड़ा नहीं है और परीक्षण ढांचे पर निर्भर बुलबुले, के रूप में विफल रहा है इस परीक्षण अंकन।

यह परीक्षण उत्पादन है:

Died on test #1  at http://localhost:7357/assets/dummy.js:304:5 
    at requireModule (http://localhost:7357/assets/vendor.js:77:29) 
    at http://localhost:7357/assets/test-loader.js:14:29: Assertion Failed: No SVG found for this/svg/is/missing 
Source:  
Error: Assertion Failed: No SVG found for this/svg/is/missing 
    at new Error (native) 
    at Error.EmberError (http://localhost:7357/assets/vendor.js:27463:23) 
    at Object.Ember.assert (http://localhost:7357/assets/vendor.js:17077:15) 
    at inlineSvg (http://localhost:7357/assets/dummy.js:94:13) 
    at Object.bindView.normalizedValue (http://localhost:7357/assets/vendor.js:20498:21) 
    at Object.SimpleHandlebarsView.render (http://localhost:7357/assets/vendor.js:23450:26) 
    at EmberRenderer_createElement [as createElement] (http://localhost:7357/assets/vendor.js:52738:16) 
    at EmberRenderer.Renderer_renderTree [as renderTree] (http://localhost:7357/assets/vendor.js:23840:24) 
    at EmberRenderer.<anonymous> (http://localhost:7357/assets/vendor.js:23917:16) 
    at DeferredActionQueues.invoke (http://localhost:7357/assets/vendor.js:13891:18) 

visit('/missing') के रूप में रिटर्न एक वादा, एक ग्रहण करेंगे कि .then(success, error) का उपयोग कर काम करेंगे, लेकिन ऐसा नहीं है।

उत्तर

10

मैं जब एक घटक renders कैसे एक उम्मीद त्रुटि के लिए परीक्षण करने के लिए की तलाश में इस सवाल के लिए आया था।

throw new Error('I am an error'); 

आपके घटक से अपेक्षित त्रुटि की जांच करने के लिए। फिर आपका परीक्षण कुछ ऐसा हो सकता है:

test('my-component should throw an error', function(assert) { 
    assert.expect(1); 

    assert.throws(() => { 
    this.render(hbs`{{my-component myVariable="XYZ"}}`); 
    }, new Error('I am an error'), 'Expect an error with this message'); 
}); 
+0

एम्बर 2.11 के रूप में, जोर से फेंकना एक चीज नहीं लगता है। https://github.com/emberjs/ember.js/pull/14898 – snewcomer

1

जैसा कि http://api.qunitjs.com/throws/ पर वर्णित है, आपको फ़ंक्शन को कॉल करने के बजाय throws पर कॉलबैक पास करना होगा।

तो:

test('throws, if the SVG is missing', function() { 
    throws(function() {visit('/missing')}, Error, "has thrown an Error"); 
}); 
संबंधित मुद्दे