Overriding modules with addMockModule
See original GitHub issueI 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:
- Created 9 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have the same issue if I put
before browser.addMockModule. If I do it after browser.get - everything works.
@zhuk-aa seriously, you just saved me from hell!