2014-05-02 11 views
5

के दौरान' त्रुटि: अप्रत्याशित अनुरोध 'grunt karma चलाते समय, निर्देशों में से एक परीक्षण टेम्पलेट लाने की कोशिश करते समय विफल रहता है। मैं एक preprocessor के रूप में ng-html2js का उपयोग कर रहा हूँ।'कर्मा एंगुलर यूनिट टेस्ट

'use strict'; 

describe('Directive: myDirective', function() { 

    // load the directive's module 
    beforeEach(module('myApp')); 
    beforeEach(module('templates')); 

    var element, 
    scope; 

    beforeEach(inject(function ($rootScope) { 
    scope = $rootScope.$new(); 
    })); 

    it('should not show search area initially', inject(function ($compile) { 
    element = angular.element('<navbar></navbar>'); 
    element = $compile(element)(scope); 
    scope.$digest(); 
    expect(element.find('.myClass').hasClass('myClass')).toBe(true); 
    })); 
}); 

जब मैं परीक्षण चलाने, मैं

Error: Unexpected request: GET /scripts/directives/myDirective/myDirective.html

मिलती है: यहाँ मेरी karma.conf.js

plugins: ['karma-chrome-launcher', 
      'karma-jasmine', 
      'ng-html2js', 
      'karma-ng-html2js-preprocessor'], 

preprocessors: { 
    'app/scripts/directives/**/*.html': 'ng-html2js' 
}, 

ngHtml2JsPreprocessor: { 
    moduleName: 'templates' 
} 

अपने परीक्षण में से कुछ है, मैं निम्नलिखित है ऐसा लगता है कि प्रीप्रोसेसर टेम्पलेट के जावास्क्रिप्ट संस्करण को सही ढंग से इंजेक्शन नहीं दे रहा है।

मैं भी beforeEach(module('')); में टेम्पलेट का पथ का उपयोग कर की कोशिश की है, लेकिन वह ऐसी त्रुटि का कारण बनता है:

Error: [$injector:modulerr] Failed to instantiate module...

मैं इसे कैसे ठीक कर सकते हैं?

उत्तर

8

मैं एक ही समस्या की तरह का था। सुनिश्चित करें कि आपके पास सटीक फ़ाइल मिलान है। Google क्रोम कंसोल खोलें और फ़ाइल पथ की जांच बिल्कुल वही है।

enter image description here

ऊपरी उदाहरण में, मैं ngHtml2JsPreprocessor.stripPrefix में एक "/" स्ट्रिंग जोड़ने के लिए था और यह काम किया। तो मुझे लगता है कि यमन के साथ, आपको

ngHtml2JsPreprocessor: { 
    moduleName: 'templates', 
    stripPrefix: 'app/' //add a slash 
} 
का उपयोग करना चाहिए
0

जब से मैं Yeoman उपकरण का उपयोग किया गया था अपने प्रोजेक्ट पाड़ के लिए, मैं अपने karma.conf.js फ़ाइल में ngHtml2JsPreprocessor विकल्प के लिए एक stripPrefix जोड़ने के लिए की जरूरत:

ngHtml2JsPreprocessor: { 
    moduleName: 'templates', 
    stripPrefix: 'app' 
} 
संबंधित मुद्दे