2016-12-26 8 views
0

私はディレクティブのジャスミンテストケースを使用していましたが、ディレクティブの出力を直接チェックするテンプレートパラメータを使用していましたが、ディレクティブをどのようにカバーするかはわかりませんテンプレートセクションは定義されていません。下記のように:ディレクティブのリンクパラメータをカバーするジャスミンテストケース

appDirective.directive('linkscriptContainer', [ 'config', function(config) { 
    return { 
     restrict : 'A', 
     scope : { 
      'value' : '@' 
     }, 
     link : function(scope, elem, attrs) { 

      //creating custom script tag 
      var customScript = document.createElement("script"); 
      customScript.type = "text/javascript"; 

      //checking if property value is available in Config object 
      //then reading the attribute value and constructing the src tag 
      if (config[attrs.value] != undefined) { 
       customScript.src = config[attrs.value]; 
      } 

      //appending the script tag in linkScriptContainer 
      elem.append(customScript); 
     } 
    }; 
}]); 

答えて

0

link機能のテストに特別な操作は必要ありません。一度、$compileelement$scope.$digest()(他の指示と同じように)link機能は単独で実行されます。

あなたのコードvar customScript = document.createElement("script");がカバー取得されていない場合、あなたはこのようにその機能をモックする必要があるかもしれません、

spyOn(document, "createElement").and.returnValue({}); 
+0

VAR customScript =のdocument.createElement( "スクリプト");コード行は自動的にカバーされています。情報のおかげで。私は以前これを知らなかった。役に立った! :) –

+0

@ApoorvTiwari私は助けることができる嬉しい:) – tanmay

関連する問題