From 411c1ae77eaeef1686274e9e4995641a8f83e765 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 26 Oct 2011 20:54:45 -0700 Subject: feat(injector): support ['$service', function($service){}] annotations for function invocation. --- test/InjectorSpec.js | 49 ++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 11 deletions(-) (limited to 'test/InjectorSpec.js') 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() {} -- cgit v1.2.3