question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overriding modules with addMockModule

See original GitHub issue

I am attempting to overwrite a module in the application with a mock module, but it does not seem to be working, and it is possible that I do not understand the documentation correctly.

In the main code, I have:

angular.module('myApp.authServices', [])
.service("myLoginService", ['$http', function($http) {
    this.authenticate = function() {
           /* Do authentication here */
         };
}]);

So, in my e2e test script, I attempted to do the following:

var authServiceMock = function() {
  angular.module('myApp.authServices', [])
  .service("myLoginService", ['$http', function($http) {
    this.authenticate = function() {
           /* Do alternative authentication here */
         };
  }]);
};

Then, I do:

browser.addMockModule("myApp.authServices", authServiceMock);

I have tried putting that line in several places - before any tests, in a beforeEach, and in the middle of tests, but it always calls the “myLoginService” from the main code. Any ideas?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
zhuk-aacommented, Aug 14, 2016

I have the same issue if I put

browser.ignoreSynchronization = true; 

before browser.addMockModule. If I do it after browser.get - everything works.

0reactions
picodothcommented, Jun 21, 2017

@zhuk-aa seriously, you just saved me from hell!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add multiple mock modules in one test with 'addMockModule'
This is working as intended, because both of your mock modules use the same module name identifier, httpBackendMock .
Read more >
addMockModule - Protractor - end-to-end testing for AngularJS
Modules will be registered after existing modules already on the page, so any module registered here will override preexisting modules with the same...
Read more >
Override Modules — Finatra 22.4.0 documentation
Defining a module is generally used to tell Guice how to instantiate an object to be provided to the object graph. When testing,...
Read more >
Overriding OCaml submodules - Thomas Jiang
Overriding OCaml submodules ... Hack ecosystem and I ran into a learning opportunity regarding extending and overriding modules in OCaml.
Read more >
protractor - UNPKG
369, * so any module registered here will override preexisting modules with the ... 384, addMockModule(name: string, script: string | Function, .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found