4

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

/directives/Statement/statement.directive.html

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

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

我在后端使用 Node + Express 并拥有app.use(express.static('client'));. 所以服务器会看到请求并在文件夹/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,这应该不是问题。


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

4

0 回答 0