私を正しい方向に導いてくれたpkozlowski.opensourceに感謝します!
私がそれをどのように解決したのか疑問に思っている人のために:
- https://npmjs.org/package/grunt-angular-templatesをプロジェクトに追加します。
- gruntビルドタスクを追加して、すべてのテンプレートをjsファイルにコンパイルします。
このJSファイルはモジュールを登録します(名前はgruntfileで構成できます)。
テンプレートに依存するすべてのテストでは、このモジュールをロードする必要があります。
テスト例:
'use strict';
describe('Component: comments', function() {
beforeEach(module('studentportalenApp'), module('app.templates'));
var element;
it('should render an error message if type is not recognized', inject(function($rootScope, $compile) {
element = angular.element('<comments></comments>');
element = $compile(element)($rootScope);
expect(element.html()).toBe('Comments directive type not recognized.');
}));
});
app.templatesモジュールで定義されているものとまったく同じURLを使用してビューを取得するように注意してください。つまり、views/ではなく/views /です。そうしないと、テンプレートのキャッシュパスと一致せず、とにかくリクエストが発生します。