NOTE: This is function is also published on window for easy access.
NOTE: Only available with jasmine.
The inject function wraps a function into an injectable function. The inject() creates new
instance of $injector
per test, which is then used for
resolving references.
See also module
Example of what a typical jasmine tests looks like with the inject method.
angular.module('myTestsModule', [], function($provide) { $provide.value('mode', 'test'); }); describe('MyApp', function() { // you can list multiple module function or aliases // which will be used in creating the injector beforeEach(module('myTestModule', function($provide) { // $provide service is configured as needed $provide.value('version', 'v1.0.1'); }); // The inject() is used to get references. it('should provide a version', inject(function(mode, version) { expect(version).toEqual('v1.0.1'); expect(mode).toEqual('test'); }); // The inject and module method can also be used inside of the it or beforeEach it('should override a version and test the new version is injected', function(){ module(function($provide) { $provide.value('version', 'overridden'); // override version here }); inject(function(version) { expect(version).toEqual('overridden'); }); )); });
inject(fns);
fns – {...Function} –
any number of functions which will be injected using the injector.