だから私は別の質問を見ました:基本的に私の問題であるディレクティブUTで必要なディレクティブコントローラーをモックする方法ですが、このスレッドへの答えは「デザインを変更する」だったようです。これを行う方法がないことを確認したかったのです。子ディレクティブで使用されるコントローラーを宣言するディレクティブがあります。私は現在、children ディレクティブのジャスミン テストを作成しようとしていますが、コントローラーに依存しているため、テストでコンパイルすることはできません。これは次のようになります。
addressModule.directive('address', ['$http', function($http){
return {
replace: false,
restrict: 'A',
scope: {
config: '='
},
template: '<div id="addressContainer">' +
'<div ng-if="!showAddressSelectionPage" basic-address config="config"/>' +
'<div ng-if="showAddressSelectionPage" address-selector addresses="standardizedAddresses"/>' +
'</div>',
controller: function($scope)
{
this.showAddressInput = function(){
$scope.showAddressSelectionPage = false;
};
this.showAddressSelection = function(){
$scope.getStandardizedAddresses();
};
this.finish = function(){
$scope.finishAddress();
};
},
link: function(scope, element, attrs) {
...
}
}
}])
子ディレクティブ:
addressModule.directive('basicAddress360', ['translationService', function(translationService){
return {
replace: true,
restrict: 'A',
scope: {
config: '='
},
template:
'...',
require: "^address360",
link: function(scope, element, attrs, addressController){
...
}
}
}])
ジャスミンテスト:
it("should do something", inject(function($compile, $rootScope){
parentHtml = '<div address/>';
subDirectiveHtml = '<div basic-address>';
parentElement = $compile(parentHtml)(rootScope);
parentScope = parentElement.scope();
directiveElement = $compile(subDirectiveHtml)(parentScope);
directiveScope = directiveElement.scope();
$rootScope.$digest();
}));
サブディレクティブをジャスミンでテストする方法はありませんか?もしそうなら、何が欠けていますか? コントローラー関数なしでディレクティブ自体をテストできたとしても、私は幸せです。