javascript - 在 Protractor 测试中覆盖常量

标签 javascript angularjs protractor

我在一个配置对象中有这两个 bool 变量,我将其传递给 Angular 应用程序的常量。

这些 bool 值都在页面解析时进行检查。如果两者都为真,它会留在页面中,如果其中一个为真,它会将用户跳转到指定页面。

看下面的代码

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;
        }]
    }
  })

我的问题是我能否重写这些常量,以便我可以在我的 Protractor 测试中测试页面是否被正确重定向?

最佳答案

也许您可以模拟您的模块并在 beforeEach 函数中提供您想要的常量。

类似的东西:

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

关于javascript - 在 Protractor 测试中覆盖常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35489169/

相关文章:

javascript - 在其他页面上显示div

angularjs - 光滑的网格包裹在指令( Angular )中,某些选项不起作用(调整大小和拖放列)

javascript - SASS 编译后浏览器同步未重新加载

javascript - 使用正则表达式进行搜索/替换

javascript - 使用 redux-saga 处理大量事件的订阅/取消订阅

angularjs - 如何在 Protractor 的 ng-repeat 中找到一个元素

angularjs - Protractor 使用的输出插件

javascript - 在Mac上使用 'sudo npm install electron -g'命令安装Electron后如何解决此错误

javascript - Symfony2 : manually submit a form without class via AJAX

GitLab CI : Error forwarding the new session Empty pool of VM for setup Capabilities 上的 Selenium Grid 错误