Karma 'Unexpected Request' when testing angular directive, even with ng-html2js

后端 未结 2 815
借酒劲吻你
借酒劲吻你 2020-12-29 04:03

After spending the last day trying to make this work, I\'ve found that I\'ve circled back around to the same error I was having at the beginning:

Error: Unex

2条回答
  •  独厮守ぢ
    2020-12-29 04:39

    So, a painstaking headache for what seems to be a two line fix. After opening Karma in Chrome (instead of PhantomJS) and looking at the source files, I noticed that when ng-html2js attaches the directive to the $templateCache it uses the entire path, not the one provided in the directive definition.

    In short, 'src/modules/test/test-directive.html.js' !== 'test-directive.html.js'.

    To achieve this, modify the karma.conf.js file ngHtml2JsProcessor to read like:

    ngHtml2JsPreprocessor: {
        stripPrefix: 'src/',
        moduleName: 'dir-templates'
    },
    

    And the directive declaration's templateUrl to look like:

    templateUrl: 'modules/test/test-directive.html'
    

提交回复
热议问题