diff options
Diffstat (limited to 'test/InjectorSpec.js')
| -rw-r--r-- | test/InjectorSpec.js | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js index ab4f3437..2c6c102a 100644 --- a/test/InjectorSpec.js +++ b/test/InjectorSpec.js @@ -1,20 +1,20 @@ 'use strict'; -describe('injector', function(){ +describe('injector', function() { var providers; var cache; var injector; var scope; - beforeEach(function(){ + beforeEach(function() { providers = extensionMap({}, 'providers'); cache = {}; scope = {}; injector = createInjector(scope, providers, cache); }); - it("should return same instance from calling provider", function(){ - providers('text', function(){ return scope.name; }); + it("should return same instance from calling provider", function() { + providers('text', function() { return scope.name; }); scope.name = 'abc'; expect(injector('text')).toEqual('abc'); expect(cache.text).toEqual('abc'); @@ -22,9 +22,9 @@ describe('injector', function(){ expect(injector('text')).toEqual('abc'); }); - it("should call function", function(){ - providers('a', function(){return 1;}); - providers('b', function(){return 2;}); + 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]; @@ -34,15 +34,15 @@ describe('injector', function(){ expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); }); - it('should inject providers', function(){ - providers('a', function(){return this.mi = 'Mi';}); + it('should inject providers', function() { + providers('a', function() {return this.mi = 'Mi';}); providers('b', function(mi){return this.name = mi+'sko';}, {$inject:['a']}); expect(injector('b')).toEqual('Misko'); expect(scope).toEqual({mi:'Mi', name:'Misko'}); }); - it('should resolve dependency graph and instantiate all services just once', function(){ + it('should resolve dependency graph and instantiate all services just once', function() { var log = []; // s1 @@ -54,12 +54,12 @@ describe('injector', function(){ // s6 - providers('s1', function(){ log.push('s1'); }, {$inject: ['s2', 's5', 's6']}); - providers('s2', function(){ log.push('s2'); }, {$inject: ['s3', 's4', 's5']}); - providers('s3', function(){ log.push('s3'); }, {$inject: ['s6']}); - providers('s4', function(){ log.push('s4'); }, {$inject: ['s3', 's5']}); - providers('s5', function(){ log.push('s5'); }); - providers('s6', function(){ log.push('s6'); }); + providers('s1', function() { log.push('s1'); }, {$inject: ['s2', 's5', 's6']}); + providers('s2', function() { log.push('s2'); }, {$inject: ['s3', 's4', 's5']}); + providers('s3', function() { log.push('s3'); }, {$inject: ['s6']}); + providers('s4', function() { log.push('s4'); }, {$inject: ['s3', 's5']}); + providers('s5', function() { log.push('s5'); }); + providers('s6', function() { log.push('s6'); }); injector('s1'); @@ -67,32 +67,32 @@ describe('injector', function(){ }); - it('should provide usefull message if no provider', function(){ - expect(function(){ + it('should provide usefull message if no provider', function() { + expect(function() { injector('idontexist'); }).toThrow("Unknown provider for 'idontexist'."); }); - it('should autostart eager services', 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}); injector.eager(); expect(log).toEqual('eager;'); expect(injector('eager')).toBe('foo'); }); - describe('annotation', function(){ - it('should return $inject', function(){ - function fn(){} + describe('annotation', function() { + it('should return $inject', function() { + function fn() {} fn.$inject = ['a']; expect(inferInjectionArgs(fn)).toBe(fn.$inject); - expect(inferInjectionArgs(function(){})).toEqual([]); - expect(inferInjectionArgs(function (){})).toEqual([]); - expect(inferInjectionArgs(function (){})).toEqual([]); - expect(inferInjectionArgs(function /* */ (){})).toEqual([]); + expect(inferInjectionArgs(function() {})).toEqual([]); + expect(inferInjectionArgs(function () {})).toEqual([]); + expect(inferInjectionArgs(function () {})).toEqual([]); + expect(inferInjectionArgs(function /* */ () {})).toEqual([]); }); - it('should create $inject', function(){ + it('should create $inject', function() { // keep the multi-line to make sure we can handle it function $f_n0 /* */( @@ -107,40 +107,40 @@ describe('injector', function(){ expect($f_n0.$inject).toEqual(['$a', 'b_', '_c', 'd']); }); - it('should handle no arg functions', function(){ - function $f_n0(){} + it('should handle no arg functions', function() { + function $f_n0() {} expect(inferInjectionArgs($f_n0)).toEqual([]); expect($f_n0.$inject).toEqual([]); }); - it('should handle args with both $ and _', function(){ + it('should handle args with both $ and _', function() { function $f_n0($a_){} expect(inferInjectionArgs($f_n0)).toEqual(['$a_']); expect($f_n0.$inject).toEqual(['$a_']); }); - it('should throw on non function arg', function(){ - expect(function(){ + it('should throw on non function arg', function() { + expect(function() { inferInjectionArgs({}); }).toThrow(); }); - it('should infer injection on services', function(){ + it('should infer injection on services', function() { var scope = angular.scope({ - a: function(){ return 'a';}, + a: function() { return 'a';}, b: function(a){ return a + 'b';} }); expect(scope.$service('b')).toEqual('ab'); }); }); - describe('inject', function(){ - it('should inject names', function(){ + describe('inject', function() { + it('should inject names', function() { expect(annotate('a', {}).$inject).toEqual(['a']); expect(annotate('a', 'b', {}).$inject).toEqual(['a', 'b']); }); - it('should inject array', function(){ + it('should inject array', function() { expect(annotate(['a'], {}).$inject).toEqual(['a']); expect(annotate(['a', 'b'], {}).$inject).toEqual(['a', 'b']); }); |
