AngularJS + Karma + Ng-html2js => Failed to instantiate module …html

后端 未结 4 953
深忆病人
深忆病人 2021-02-02 09:28

I can\'t make Karma working for directives that have external templates.

Here is my karma configuration file :

pr         


        
4条回答
  •  暖寄归人
    2021-02-02 10:22

    You can have the pre-processor cache your templates to a module, which can then be included prior to your tests:

    karma.conf.js

    files: [
      ...
      'app/**/*.html'
    ],
    
    preprocessors: {
      'app/**/*.html': ['ng-html2js']
    },
    
    ngHtml2JsPreprocessor: {
       moduleName: 'templates'
    },
    

    directive file

    ...
    templateUrl: 'app/path-to-your/template.html',
    ...
    

    spec file

    describe('My directive', function() {
    
      beforeEach(module('templates'));
      ...
    });
    

提交回复
热议问题