Within my module, there exists a greet
factory that is attached:
angular.module('someModule', [])
.factory('greet', function(name) {
return function() {
return 'Hi ' + name + '!';
}
});
This factory relies on the injection of a name
, which is a value specified in a separate module.
angular.module('someOtherModule', [])
.value('name', 'example');
During the testing phase of this module, I aim to be able to modify the injected name
value multiple times (once per test), allowing my tests to resemble the following structure:
// Within my test file…
// Set up the module being tested (`greet`) and simulate the other module containing a `name` value
beforeEach(mocks.module('someModule', function ($provider) {
$provider.value('name', 'Bob');
}));
var greet
beforeEach(mocks.inject(function ($injector) {
greet = $injector.get('greet');
});
it('should display "Bob"', function () {
expect(greet()).toBe('Hi Bob!');
});
// Subsequently, alter the `name` value to now be "Bar"
it('should display "Bar"', function () {
expect(greet()).toBe('Hi Bar!');
});
Is it achievable?
The integration of these two modules takes place within my app module:
angular.module('app', ['someModule', 'someOtherModule'])