karma-ng-html2js-preprocessor未正确设置路径

时间:2015-07-23 16:49:27

标签: javascript angularjs karma-runner ng-html2js

我正在测试我的statement指令。它有一个templateUrl

/directives/Statement/statement.directive.html

我的应用程序的文件结构:

- tango
  - client
    - directives
      - Statement
        - statement.directive.html
  - server
  - test

我在后端使用Node + Express并拥有app.use(express.static('client'));So服务器会看到/directives/Statement/statement.directive.html的请求,并在client文件夹下找到它。

以前我没有提供静态文件,并且:

templateUrl: /client/directives/Statement/statement.directive.html

此时,我的测试运行正常。但是,既然我正在client静态地提供服务并且相应地更新了templateUrl,那么我的测试就失败了。这是我收到的错误消息:

Error: Unexpected request: GET /directives/Statement/statement.directive.html
No more request expected
    at $httpBackend (/Users/azerner/code/tango/test/lib/angular-mocks.js:1211:9)
    at sendReq (/Users/azerner/code/tango/lib/angular.js:10335:9)
    at serverRequest (/Users/azerner/code/tango/lib/angular.js:10047:16)
    at processQueue (/Users/azerner/code/tango/lib/angular.js:14569:28)
    at /Users/azerner/code/tango/lib/angular.js:14585:27
    at Scope.$eval (/Users/azerner/code/tango/lib/angular.js:15848:28)
    at Scope.$digest (/Users/azerner/code/tango/lib/angular.js:15659:31)
    at Object.<anonymous> (/Users/azerner/code/tango/test/unit/directives/statement.directive.js:18:11)
    at Object.invoke (/Users/azerner/code/tango/lib/angular.js:4452:17)
    at Object.workFn (/Users/azerner/code/tango/test/lib/angular-mocks.js:2420:20)
Error: Declaration Location
    at window.inject.angular.mock.inject (/Users/azerner/code/tango/test/lib/angular-mocks.js:2391:25)
    at Suite.<anonymous> (/Users/azerner/code/tango/test/unit/directives/statement.directive.js:7:14)
    at /Users/azerner/code/tango/test/unit/directives/statement.directive.js:1:1
TypeError: Cannot read property 'vm' of undefined
    at Object.<anonymous> (/Users/azerner/code/tango/test/unit/directives/statement.directive.js:22:22)
TypeError: Cannot read property 'statement' of undefined
    at Object.<anonymous> (/Users/azerner/code/tango/test/unit/directives/statement.directive.js:27:14)

我正在使用karma-ng-html2js-preprocessor。在karma.conf.js我有:

files: [
  'lib/jquery.js',
  'lib/angular.js',
  'lib/angular-ui-router.min.js',
  'test/lib/angular-mocks.js',
  'client/**/*.html',
  'client/**/*.js',
  'test/unit/**/*.js'
],

ngHtml2JsPreprocessor: {
  moduleName: 'templates',
  cacheIdFromPath: function(filepath) {
    console.log(filepath);
    return filepath;
  },
  stripPrefix: 'client'
},

它正在退出:

client/directives/Statement/statement.directive.html
client/templates/login.html
client/templates/signup.html
client/templates/home.html
client/templates/tango.html

我正在剥离client前缀。所以我认为它应该设置一个关键

/directives/Statement/statement.directive.html

在我的$templateCache中,因此

GET /directives/Statement/statement.directive.html

请求应由$templateCache“拦截”(?),这应该不是问题。

问题是什么,我该如何解决?

0 个答案:

没有答案