diff options
| author | Misko Hevery | 2011-10-26 20:54:45 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 16:39:32 -0800 |
| commit | 411c1ae77eaeef1686274e9e4995641a8f83e765 (patch) | |
| tree | 8d72f5b5ad3e3684a16420d6e433cc41f500a55a /test/InjectorSpec.js | |
| parent | d12df0d360fe0dabdca3591654327834bee2803b (diff) | |
| download | angular.js-411c1ae77eaeef1686274e9e4995641a8f83e765.tar.bz2 | |
feat(injector): support ['$service', function($service){}] annotations for function invocation.
Diffstat (limited to 'test/InjectorSpec.js')
| -rw-r--r-- | test/InjectorSpec.js | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js index fe1993e5..46c9897b 100644 --- a/test/InjectorSpec.js +++ b/test/InjectorSpec.js @@ -18,17 +18,6 @@ describe('injector', function() { expect(injector('instance')).toEqual(original); }); - it("should call function", function() { - providers('a', function() {return 1;}); - providers('b', function() {return 2;}); - var args; - function fn(a, b, c, d) { - args = [this, a, b, c, d]; - } - fn.$inject = ['a', 'b']; - injector.invoke({name:"this"}, fn, [3, 4]); - expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); - }); it('should inject providers', function() { providers('a', function() {return 'Mi';}); @@ -82,6 +71,44 @@ describe('injector', function() { expect(injector('eager')).toBe('foo'); }); + describe('invoke', function(){ + var args; + + beforeEach(function(){ + args = null; + providers('a', function() {return 1;}); + providers('b', function() {return 2;}); + }); + + + function fn(a, b, c, d) { + args = [this, a, b, c, d]; + } + + + it('should call function', function() { + fn.$inject = ['a', 'b']; + injector.invoke({name:"this"}, fn, [3, 4]); + expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); + }); + + + it('should treat array as annotations', function(){ + injector.invoke({name:"this"}, ['a', 'b', fn], [3, 4]); + expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); + }); + + + it('should fail with errors if not function or array', function(){ + expect(function(){ + injector.invoke({}, {}); + }).toThrow("Argument 'fn' is not a function, got Object"); + expect(function(){ + injector.invoke({}, ['a', 123]); + }).toThrow("Argument 'fn' is not a function, got number"); + }); + }); + describe('annotation', function() { it('should return $inject', function() { function fn() {} |
