【发布时间】:2015-07-20 19:16:28
【问题描述】:
尝试对我的指令运行单元测试时,我不断收到此错误:
Error: Unexpected request: GET /assets/partials/project-brand.html
No more request expected
我对可能导致此问题的原因感到困惑。
这是我的 karma.conf.js:
files: [
'js/*.js',
'partials/*.html',
'../tests/client/unit/*.js'
]
preprocessors: {
'partials/*.html': ['ng-html2js']
},
ngHtml2JsPreprocessor: {
stripPrefix: 'public/'
}
我的文件组织:
-public
--js
---directives.js
--partials
---project-brand.html
-tests
--client
---unit
----directives.js
我的指令:
.directive('projectBrand', [function() {
return {
restrict: 'E',
scope: {
brand: '=',
projectId: '=',
index: '='
},
templateUrl: '/assets/partials/project-brand.html',
controller: ['$scope', function($scope){
$scope.isWorking = false;
}]}}])
最后,我的指令测试文件:
beforeEach(module('app'));
beforeEach(module('partials/project-brand.html'));
beforeEach(inject(function(_$compile_, _$rootScope_){
$compile = _$compile_;
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$scope.brand = {id: 1};
$scope.project.id = 1;
$scope.index = 0;
element = angular.element('<project-brand brand="brand" project-id="project.id" index="$index"></project-brand>');
directive = $compile(element)($scope);
$scope.$apply();
}));
如果有人有任何建议,我将不胜感激!
【问题讨论】:
-
我想你可能还有更多的指令测试文件。还是这样?
-
是的,为了清楚起见,我会进行编辑,但没有太多其他内容
-
只有
/assets出现在你的 templateUrl 中。 -
@charlietfl 那么我应该改变什么?
-
不确定服务器路由是如何配置的,但您是否尝试过不使用 templteUrl 中的
assets目录?
标签: angularjs unit-testing angularjs-directive karma-jasmine ng-html2js