aboutsummaryrefslogtreecommitdiffstats
path: root/test/InjectorSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2011-02-16 19:18:35 -0500
committerMisko Hevery2011-02-18 13:14:07 -0800
commit7d4aee31bb202e9b050fc15c56cfc33c46b9eaf5 (patch)
tree3c503f5ac9104983d3ed665da76a464142e94a53 /test/InjectorSpec.js
parent7a54d2791ff4de5808970f3862114f84121115b5 (diff)
downloadangular.js-7d4aee31bb202e9b050fc15c56cfc33c46b9eaf5.tar.bz2
Auto create $inject property form the argument names. Any arg starting with $ or _ will be injected
Diffstat (limited to 'test/InjectorSpec.js')
-rw-r--r--test/InjectorSpec.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js
index 765003cf..c876f188 100644
--- a/test/InjectorSpec.js
+++ b/test/InjectorSpec.js
@@ -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();
+ });
+
+ });
});