Quando si esegue grunt karma
, un test su una delle direttive non riesce quando tenta di recuperare il modello. Sto usando ng-html2js come preprocessore. Ecco alcuni dei miei karma.conf.js'Errore: richiesta inattesa' durante il test dell'unità angolare Karma
plugins: ['karma-chrome-launcher',
'karma-jasmine',
'ng-html2js',
'karma-ng-html2js-preprocessor'],
preprocessors: {
'app/scripts/directives/**/*.html': 'ng-html2js'
},
ngHtml2JsPreprocessor: {
moduleName: 'templates'
}
Nella mia prova, ho il seguente:
'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);
}));
});
Quando eseguo il test, ottengo
Error: Unexpected request: GET /scripts/directives/myDirective/myDirective.html
Sembra che il preprocessore non stia iniettando correttamente la versione javascript del modello.
ho anche provato ad utilizzare il percorso del modello nella beforeEach(module(''));
ma che causa un errore che recita:
Error: [$injector:modulerr] Failed to instantiate module...
Come posso risolvere questo problema?