0

ディレクティブで単体テストを実行しようとすると、このエラーが発生し続けます。

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();
}));

誰かが何か提案があれば、私は本当に感謝しています!

4

2 に答える 2

0

これは、angular が templateUrl を処理する方法に関する問題の 1 つです。私は同じ問題に直面し、ファイル構造を見て修正しました。'partials/project-brand.html' を試してください。これで直ったかどうか教えてください。

于 2015-07-21T19:43:00.743 に答える