0

すべてのテンプレートが myindex.htmlにあり、それぞれが独自の<script type="text/ng-template" id="foo">...</script>ブロック内$templatecacheにある場合、Jasmine がそれらの存在を認識できるようにするにはどうすればよいですか?

現在、Jasmine はすべてのtemplateUrl値をリモート パスであるかのように扱っています。karma-ng-html2js-preprocessorを調べましたが、これは個別のテンプレート ファイルを$templatecacheスクリプト ブロックではなく に取得するためのもののようです。

インライン テンプレートがどのように読み込まれるかを示すプランカーを次に示します。

4

1 に答える 1

0

karma-ng-template-preprocessorモジュールを使用します。

HTML ファイルを取得<script type="ng/template">して AngularJS テンプレート キャッシュに入れるためのプリプロセッサ アイデアとコード スニペットについて karma-ng-html2js-preprocessor に感謝します

たとえば、karma.conf.js を次のように設定します。

// preprocess HTML files before serving them to phantomJS
    preprocessors: {'app/**/*.html': 'ng-template'},
// include HTML files in the karma session
    files: ['**/*.html'],

// if you have defined plugins explicitly, add karma-ng-template-script-to-template-cache-preprocessor 
// plugins: ['karma-ng-template-preprocessor'] 

ngTemplatePreprocessor: { moduleName: 'inlineTemplates'}

次のようにテストで使用します。

function foo()
  {
  beforeEach(module('inlineTemplates'));    
  }

describe('example test', foo);

参考文献

于 2017-07-05T15:02:28.310 に答える