mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-23 11:37:38 +08:00
Auto create $inject property form the argument names. Any arg starting with $ or _ will be injected
This commit is contained in:
@@ -53,9 +53,56 @@ describe('injector', function(){
|
||||
|
||||
it('should autostart eager services', function(){
|
||||
var log = '';
|
||||
providers('eager', function(){log += 'eager;'; return 'foo'}, {$eager: true});
|
||||
providers('eager', function(){log += 'eager;'; return 'foo';}, {$eager: true});
|
||||
inject();
|
||||
expect(log).toEqual('eager;');
|
||||
expect(inject('eager')).toBe('foo');
|
||||
});
|
||||
|
||||
describe('annotation', function(){
|
||||
it('should return $inject', function(){
|
||||
function fn(){};
|
||||
fn.$inject = ['a'];
|
||||
expect(injectionArgs(fn)).toBe(fn.$inject);
|
||||
expect(injectionArgs(function(){})).toEqual([]);
|
||||
});
|
||||
|
||||
it('should create $inject', function(){
|
||||
// keep the multi-line to make sure we can handle it
|
||||
function $f_n0(
|
||||
$a, // x, <-- looks like an arg but it is a comment
|
||||
b_, /* z, <-- looks like an arg but it is a
|
||||
multi-line comment
|
||||
function (a, b){}
|
||||
*/
|
||||
/* {some type} */ c){ extraParans();};
|
||||
expect(injectionArgs($f_n0)).toEqual(['$a', 'b']);
|
||||
expect($f_n0.$inject).toEqual(['$a', 'b']);
|
||||
});
|
||||
|
||||
it('should handle no arg functions', function(){
|
||||
function $f_n0(){};
|
||||
expect(injectionArgs($f_n0)).toEqual([]);
|
||||
expect($f_n0.$inject).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle args with both $ and _', function(){
|
||||
function $f_n0($a_){};
|
||||
expect(injectionArgs($f_n0)).toEqual(['$a']);
|
||||
expect($f_n0.$inject).toEqual(['$a']);
|
||||
});
|
||||
|
||||
it('should throw on non function arg', function(){
|
||||
expect(function(){
|
||||
injectionArgs({});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
it('should throw on injectable after non-injectable arg', function(){
|
||||
expect(function(){
|
||||
injectionArgs(function($a, b_, nonInject, d_){});
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user