2016-02-18 12 views
5

私は角度アプリケーションの定数に渡す設定オブジェクトにこれらの2つのブール変数を持っています。分度器テストのオーバーライド定数

これらのブール値は、ページが解決された時点でチェックされます。両方が真であれば、それはページ内にとどまり、一方または他方が真であれば、ユーザを指定されたページにバウンスさせる。

私は、解決の機能でこれらをチェック

angular 
.module('ecardGeneratorPrototype') 
.constant('config', 
{ 
    "enable-file-upload": true, 
    "enable-webcam": true 

以下のコードを参照してください。

.when('/home', { 
    templateUrl: 'app/home/home.html', 
    controller: 'HomeController', 
    controllerAs: 'home', 
    resolve : { 
     choice: ['$route', '$window', 'config', function ($route, $window, config) { 
      if (config["enable-file-upload"] && config["enable-webcam"]){ 
       //return 
       return; 
      } 
      else 
      { 
       if (config["enable-file-upload"]){ 
       //go to the file upload page 
       //$log("display the file upload page"); 
       $window.location.href = '#/file-upload'; 
       } 
       else if (config["enable-webcam"]){ 
       //$log("display the webcam page"); 
       $window.location.href = '#/webcam'; 
       } 
      } 
      return; 
     }] 
    } 
    }) 

私の質問は、私はページがで正しくリダイレ​​クトされているテストすることができますので、私はこれらの定数を上書きすることができています私の分度器テスト?

答えて

0

モジュールをモックし、beforeEach関数で必要な定数を与えることができます。

そのような何か:

beforeEach(angular.mock.module("ecardGeneratorPrototype", function ($provide) { 
 
    $provide.constant("enable-file-upload", false); 
 
}));

関連する問題