Karma+Jasmine で Angular ディレクティブをテストしようとしています。したがって、私のディレクティブにあるようtemplateUrl
に、テンプレートをkarma-ng-html2js-preprocessorでキャッシュする必要があります。私のkarma.conf.jsファイル:
...
files: [
...
'static/views/**/*.html', // to match my directive template
...
],
preprocessors: {
'/static/views/**/*.html': ['ng-html2js] // to catch the filename as specified in templateUrl
},
ngHtml2JsPreprocessor: {
moduleName: 'templates'
}
...
そして私のジャスミン仕様:
describe('Directive unittesting', function() {
beforeEach(module('myModule'));
beforeEach(module('templates'));
var $compile, $scope;
beforeEach(inject(function(_$compile_, _$rootScope_) {
$compile = _$compile_;
$scope = _$rootScope_.$new();
}));
it('Replaces the element with the appropriate content', function() {
var element = $compile("<my-directive></my-directive>")($scope);
expect(element.html()).toContain("text to contain");
});
});
しかし、何らかの理由で私のtemplates
モジュールを注入できないようです: TypeError: undefined is not a function (evaluating '$compile(...
. それらを正しく連携させるにはどうすればよいですか?