2015-07-10 74 views
1

我很新的Javascript和量角器。仍然試圖讓我的頭簡單的語法,所以原諒我,如果我在這裏基地的方式。在量角器中,是否可以運行Angular模塊功能?

所以我們的角度應用程序,有一個工廠生成吐司消息模塊。我想在我的E2E測試期間禁用所有Toast消息。我們在工廠有一個功能來禁用吐司。這裏有一些簡化的代碼。

//the module 
var module = angular.module('toast',[]); 

//the factory 
module.factory('tf',[function tf(){ 

//factory code 

//the function within the module's factory 
moduleFactory.enable = function(enable){ 
     isEnabled = enable; 
    }; 
}]); 

我的問題是,我可以訪問量角器中的該功能將其變爲false?

我一直在尋找,似乎嘲笑是如何做到這一點。類似於您禁用角動畫的方法。

// Disable animations so e2e tests run more quickly 
var disableNgAnimate = function() { 
angular.module('disableNgAnimate', []).run(['$animate', function($animate) { 
$animate.enabled(false); 
}]); 
}; 

browser.addMockModule('disableNgAnimate', disableNgAnimate); 

不過,我與模塊內訪問該工廠的函數的語法掙扎...任何幫助,將不勝感激。

回答

1

我相信我找到了解決方案給其他任何可能有類似問題的解決方案。

使用量角器的executeScript函數。

browser.executeScript(function() 
{ 
    return angular.element(document).injector().get('toastFactory').enableToasts(false); 
}); 
相關問題