Javascript karma-ng-html2js-预处理器无法获取模板

Javascript karma-ng-html2js-预处理器无法获取模板,javascript,angularjs,jasmine,karma-jasmine,ng-html2js,Javascript,Angularjs,Jasmine,Karma Jasmine,Ng Html2js,我正在尝试为使用templateUrl的简单指令编写一个测试。这里是我的文件夹结构: src main webapp assets css js partials cart name.html items.html

我正在尝试为使用
templateUrl
的简单指令编写一个测试。这里是我的文件夹结构:

src
    main
        webapp
            assets
                css
                js
            partials
                cart
                    name.html
                    items.html
                    shipping.html
                index.html
指令(用于name.html):

Karma配置文件:

module.exports = function(config) {
    config.set({

        basePath: '',
        frameworks: ['jasmine'],    

        // list of files / patterns to load in the browser
        files: [
            '../../main/webapp/assets/js/angular.js',
            '../../main/webapp/assets/js/main.min.js',
            './assets/js/angular-mocks.js',
            './specs.js',
            '../../main/webapp/partials/*/*.html'
        ],

        // list of plugins to load
        plugins : [
            'karma-htmlfile-reporter',
            'karma-firefox-launcher',        
            'karma-jasmine',
            'karma-ng-html2js-preprocessor'
        ],    

        // list of files to exclude
        exclude: [
        ],    

        preprocessors: {
            '../../main/webapp/cart/*/*.html': ['ng-html2js']
        },

        ngHtml2JsPreprocessor: {
            //stripPrefix: "",
            //prependPrefix: "",

            // the name of the Angular module to create
            moduleName: "my.templates"
        },

        // test results reporter to use
        // possible values: 'dots', 'progress'
        // available reporters: https://npmjs.org/browse/keyword/karma-reporter
        reporters: ['progress', 'html'],    

        // web server port
        port: 9876,           

        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,

        // start these browsers
        // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
        browsers: ['Firefox'],

        // Continuous Integration mode
        // if true, Karma captures browsers, runs the tests and exits
        singleRun: false

    });
};
单元测试:

describe("Directive:", function () { 

    beforeEach(angular.mock.module("cartApp"));

      describe("template", function () {
          var $compile;
          var $scope;
          var $httpBackend;

         // Load the templates module
         beforeEach(module('my.templates'));    

         // Angular strips the underscores when injecting
         beforeEach(inject(function(_$compile_, _$rootScope_) {
             $compile = _$compile_;
             $scope = _$rootScope_.$new();
         }));

         it("should render drv-cart-name",
         inject(function() {
            // $compile the template, and pass in the $scope.
            // This will find your directive and run everything
            var template = $compile("<drv-cart-name></drv-cart-name>")($scope);     
            // Now run a $digest cycle to update your template with new data
            $scope.$digest();

            // Render the template as a string
            var templateAsHtml = template.html();

            //  // Verify that the $scope variables are in the template
            expect(element.templateAsHtml()).toContain('<p class="user">');

         }));

     });
 });

尝试了另一种编写测试的方式,但仍然存在相同的错误:

describe('Directive', function() {

    beforeEach(function() {
       module('cartApp');
       module('ngMockE2E'); //<-- IMPORTANT!

       inject(function(_$httpBackend_) {
        $httpBackend = _$httpBackend_;
        $httpBackend.whenGET('cart/name.html').passThrough();
       });
    });    

    var element, controller, scope;

    beforeEach(inject(function($rootScope, $controller, $compile) {
        scope = $rootScope.$new();

        element = angular.element('<drv-cart-name></drv-cart-name>');
        element = $compile(element)(scope);
        scope.$digest();
    }));

    it('should contain a input class', function() {
        expect(element.html()).toContain('<p class="input">');
    });
});

Error: Unexpected request: GET cart/name.html No more request expected $httpBackend
描述('Directive',function()){
beforeach(函数(){
模块(“cartApp”);

module('ngMockE2E');//尝试将预处理器配置更改为使用双星号(适用于任何文件夹层次结构)--'../../main/webapp/cart/***.html':['ng-html2js']@EitanPeer-感谢您的建议,刚刚尝试过,仍然会得到相同的错误:“错误:意外请求:get…..“使用”--日志级调试运行”。ng-html2js预处理器是否应用于您期望的文件?您应该看到一行内容为-DEBUG[preprocessor.html2js]:处理“path/to/your/html/file.html”尝试更改预处理器配置以使用双星号(适用于任何文件夹层次结构)-“../../main/webapp/cart/***.html”:['ng-html2js']@EitanPeer-感谢您的建议,刚刚尝试过,仍然得到相同的错误:“错误:意外请求:get…”“与”--日志级调试一起运行”。ng-html2js预处理器是否应用于您期望的文件?您应该看到一行内容为-debug[preprocessor.html2js]:Processing“path/to/your/html/file.html”尝试将预处理器配置更改为使用双星号(适用于任何文件夹层次结构)--'../../main/webapp/cart/***.html':['ng-html2js']@EitanPeer-感谢您的建议,刚刚尝试过,仍然会收到相同的错误:“错误:意外请求:get…”“与一起运行”--日志级调试”。ng-html2js预处理器是否应用于您期望的文件?您应该看到一行内容为-DEBUG[preprocessor.html2js]:Processing“path/to/your/html/file.html”
Error: Unexpected request: GET cart/name.html No more request expected $httpBackend@
describe('Directive', function() {

    beforeEach(function() {
       module('cartApp');
       module('ngMockE2E'); //<-- IMPORTANT!

       inject(function(_$httpBackend_) {
        $httpBackend = _$httpBackend_;
        $httpBackend.whenGET('cart/name.html').passThrough();
       });
    });    

    var element, controller, scope;

    beforeEach(inject(function($rootScope, $controller, $compile) {
        scope = $rootScope.$new();

        element = angular.element('<drv-cart-name></drv-cart-name>');
        element = $compile(element)(scope);
        scope.$digest();
    }));

    it('should contain a input class', function() {
        expect(element.html()).toContain('<p class="input">');
    });
});

Error: Unexpected request: GET cart/name.html No more request expected $httpBackend