Override constants in test

I have these two booleans in a configuration object that I pass to the angular application constant.

These logical values ​​are checked at the point allowed by the page. If both of them are true, it remains on the page, and if one or the other is true, it bounces the user to the specified page.

See code below

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

Then I check them in the resolution function:

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

My question is: can I override these constants to check if the pages in my protractor tests are redirected correctly?

+5
source share
1 answer

Perhaps you can make fun of your module and provide the constant you want in the beforeEach function.

Something like that:

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

Source: https://habr.com/ru/post/1243336/


All Articles