0

If all of my templates are in my index.html, with each inside its own <script type="text/ng-template" id="foo">...</script> block, how can I get them into the $templatecache so that Jasmine knows they exist?

Currently, Jasmine treats all of my templateUrl values as if they were all remote paths. I have looked through karma-ng-html2js-preprocessor, but it appears that this is for getting discrete template files into $templatecache, rather than script blocks.

Here is a plunker showing how the inline templates are loaded.

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 回答