2016-02-18 23 views
5

Bu iki boole değişkeni, açısal uygulamanın sabitine geçtiğim bir yapılandırma nesnesinde var.İletki Testindeki Sabitleri Geçersiz Kılma

Bu booleanlar, sayfanın çözdüğü noktada denetlenir. Her ikisi de doğruysa, sayfada kalır ve biri veya diğeri doğruysa, kullanıcıyı belirtilen bir sayfaya döndürür.

Sonra bir çözümleme fonksiyonu bu kontrol

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

aşağıdaki kodu bakınız:

Sorum doğru yönlendirilmekte olduğu Sayfaları test edebilirsiniz yani bu sabitleri geçersiz kılabilir edilir
.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; 
     }] 
    } 
    }) 

iletkem test eder?

cevap

0

Belki de modülünüzle dalga geçebilir ve bir beforeEach işlevinde istediğiniz sabitleri sağlayabilirsiniz. Böyle

şey:

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