尝试对我的指令运行单元测试时,我不断收到此错误:
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();
}));
如果有人有一些建议,我将不胜感激!