diff options
Diffstat (limited to 'test/InjectorSpec.js')
| -rw-r--r-- | test/InjectorSpec.js | 49 | 
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(); +    }); + +  });  }); | 
