我無法讓Karma適用於具有外部模板的指令。AngularJS + Karma + Ng-html2js =>無法實例化模塊... html
這裏是我的人緣配置文件:
preprocessors: {
'directives/loading/templates/loading.html': 'ng-html2js'
},
files: [
...
'directives/loading/templates/loading.html',
]
ngHtml2JsPreprocessor: {
prependPrefix: '/app/'
},
在指令文件:
...
templateUrl: '/app/directives/loading/templates/loading.html'
...
在規範文件中:
describe('Loading directive', function() {
...
beforeEach(module('/app/directives/loading/templates/loading.html'));
...
});
我收到以下錯誤:
Failed to instantiate module /app/directives/loading/templates/loading.html due to: Error: No module: /app/directives/loading/templates/loading.html
如果我修改了卡瑪 - NG-html2js預處理程序的源代碼,以打印生成的 文件的結果,我得到:
angular.module('/app/directives/loading/templates/loading.html', []).run(function($templateCache) {
$templateCache.put('/app/directives/loading/templates/loading.html',
'<div ng-hide="hideLoading" class="loading_panel">\n' +
' <div class="center">\n' +
' <div class="content">\n' +
' <span ng-transclude></span>\n' +
' <canvas width="32" height="32"></canvas>\n' +
' </div>\n' +
' </div>\n' +
'</div>');
});
如此看來,生成的JS文件是正確的但不是因果報應加載中...
另外,如果我用--log級調試,這裏涉及到模板中的臺詞:
DEBUG [preprocessor.html2js]: Processing "/home/rightink/public_html/bo2/master/web/app/directives/loading/templates/loading.html"
DEBUG [watcher]: Resolved files:
/correct/path/to/the/app/directives/loading/templates/loading.html.js
我失去的東西?
感謝,
試圖找出通過在https://github.com/vojtajina/ng-directive-testing存儲庫。 – srigi
我學會了用這個回購測試AngularJS指令。所以我從一開始就受到啓發。 – Vincent
您是否找到解決方案? –