I am trying to figure out how the function angular.mock.module (often aliased to window.module) works. I understand its main usage is loading a module in your tests; that is easy:
beforeEach(angular.mock.module("mymodule"));
This will load myhmodule before each it in my jasmine specs.
Another usage of module is to mock services/factories/values inside a certain module. Assuming mymodule has a value called foo of value 42 I can, in my specs, go like this:
beforeEach(angular.mock.module("mymodule")); // this loads the module
// whereas this mocks the value of foo
beforeEach(module(function($provide) {
$provide.value("foo", 43);
});
My question is now the following: how does module know what module to address when mocking using the $provide service? In fact, in my test, I could have written:
beforeEach(angular.mock.module("mymodule"));
beforeEach(angular.mock.module("anothermodule"));
beforeEach(module(function($provide) {
$provide.value("foo", 43);
});
Would this last snippet provide a foo=43 to mymodule or anothermodule?
Aucun commentaire:
Enregistrer un commentaire