gpt4 book ai didi

javascript - 在 Protractor 测试中覆盖常量

转载 作者:搜寻专家 更新时间:2023-11-01 04:40:25 26 4
gpt4 key购买 nike

我在一个配置对象中有这两个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com