I'm testing my statement directive. It has a templateUrl of:
/directives/Statement/statement.directive.html
My app's file structure:
- tango
- client
- directives
- Statement
- statement.directive.html
- server
- test
I'm using Node + Express on the backend and have app.use(express.static('client'));. So the server will see the request for /directives/Statement/statement.directive.html and find it under the client folder.
Previously I wasn't serving static files and had:
templateUrl: /client/directives/Statement/statement.directive.html
At this point, my tests were running fine. However, now that I'm serving things under client statically and and have updated the templateUrl accordingly, my tests are failing. This is the error message I'm getting:
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)
I'm using karma-ng-html2js-preprocessor. In karma.conf.js I have:
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'
},
It's logging out:
client/directives/Statement/statement.directive.html
client/templates/login.html
client/templates/signup.html
client/templates/home.html
client/templates/tango.html
And I'm stripping the client prefix. So I'd think that it should set a key of
/directives/Statement/statement.directive.html
in my $templateCache, and thus the
GET /directives/Statement/statement.directive.html
request should be "intercepted"(?) by $templateCache and this shouldn't be a problem.
What is the problem, and how could I fix it?