I\'m trying to use Protractor\'s addMockModule() to mock a simple AngularJS module and override a variable:
Here is my HTML:
According to Juliemr in this post:
https://github.com/angular/protractor/issues/509
" the code that is run in the mockedModule is run in a separate context from the test. One is in the browser, one is in the node.js process running the test "
Put declaration of mockedValue inside it() and enable angular synchronization
it('should override services via mock modules', function () {
ptor = protractor.getInstance();
// When ignoreSynchronization is true mocking doesn't work
ptor.ignoreSynchronization = false;
browser.addMockModule('myModule', function () {
var module = angular.module('myModule').config(['$provide', function ($provide) {
$provide.constant('myValue', 'newMockedValue');
}])
});
browser.get('http://localhost:57627/page1.html');
expect(element(by.binding("myValue")).getText()).toBe("newMockedValue");
});