diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 29 | ||||
| -rw-r--r-- | test/BinderSpec.js | 16 | ||||
| -rw-r--r-- | test/InjectorSpec.js | 120 | ||||
| -rw-r--r-- | test/ResourceSpec.js | 6 | ||||
| -rw-r--r-- | test/markupSpec.js | 2 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 2 | ||||
| -rw-r--r-- | test/service/compilerSpec.js | 10 | ||||
| -rw-r--r-- | test/service/cookiesSpec.js | 4 | ||||
| -rw-r--r-- | test/service/deferSpec.js | 4 | ||||
| -rw-r--r-- | test/service/exceptionHandlerSpec.js | 6 | ||||
| -rw-r--r-- | test/service/locationSpec.js | 18 | ||||
| -rw-r--r-- | test/service/logSpec.js | 8 | ||||
| -rw-r--r-- | test/service/scopeSpec.js | 18 | ||||
| -rw-r--r-- | test/service/xhr.bulkSpec.js | 10 | ||||
| -rw-r--r-- | test/service/xhr.cacheSpec.js | 12 | ||||
| -rw-r--r-- | test/service/xhr.errorSpec.js | 8 | ||||
| -rw-r--r-- | test/service/xhrSpec.js | 8 | ||||
| -rw-r--r-- | test/testabilityPatch.js | 28 | ||||
| -rw-r--r-- | test/widget/inputSpec.js | 6 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 2 |
20 files changed, 148 insertions, 169 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index a957fcf7..8902c2a9 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -375,9 +375,9 @@ describe('angular', function() { describe('angular service', function() { - it('should override services', inject(function(service){ - service('fake', function() { return 'old'; }); - service('fake', function() { return 'new'; }); + it('should override services', inject(function($provide){ + $provide.value('fake', 'old'); + $provide.value('fake', 'new'); }, function(fake) { expect(fake).toEqual('new'); })); @@ -401,22 +401,23 @@ describe('angular', function() { expect(result.third).toBeTruthy(); }); - it('should inject dependencies specified by $inject', function() { - angular.service('svc1', function() { return 'svc1'; }); - angular.service('svc2', function(svc1) { return 'svc2-' + svc1; }, {$inject: ['svc1']}); - expect(createInjector()('svc2')).toEqual('svc2-svc1'); - }); - it('should inject dependencies specified by $inject and ignore function argument name', function() { - angular.service('svc1', function() { return 'svc1'; }); - angular.service('svc2', function(foo) { return 'svc2-' + foo; }, {$inject: ['svc1']}); - expect(createInjector()('svc2')).toEqual('svc2-svc1'); + expect(angular.injector(function($provide){ + $provide.factory('svc1', function() { return 'svc1'; }); + $provide.factory('svc2', ['svc1', function(s) { return 'svc2-' + s; }]); + })('svc2')).toEqual('svc2-svc1'); }); it('should eagerly instantiate a service if $eager is true', function() { var log = []; - angular.service('svc1', function() { log.push('svc1'); }, {$eager: true}); - createInjector(angularService); + angular.injector(function($provide){ + $provide.service('svc1', function() { + this.$get = function(){ + log.push('svc1'); + } + this.$eager = true; + }); + }); expect(log).toEqual(['svc1']); }); }); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index 6a459074..495d98a8 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -222,8 +222,8 @@ describe('Binder', function() { })); it('IfTextBindingThrowsErrorDecorateTheSpan', inject( - function(service){ - service('$exceptionHandler', $exceptionHandlerMockFactory); + function($provide){ + $provide.factory('$exceptionHandler', $exceptionHandlerMockFactory); }, function($rootScope, $exceptionHandler, $compile) { $compile('<div>{{error.throw()}}</div>', null, true)($rootScope); @@ -245,8 +245,8 @@ describe('Binder', function() { }) ); - it('IfAttrBindingThrowsErrorDecorateTheAttribute', inject(function(service){ - service('$exceptionHandler', $exceptionHandlerMockFactory); + it('IfAttrBindingThrowsErrorDecorateTheAttribute', inject(function($provide){ + $provide.factory('$exceptionHandler', $exceptionHandlerMockFactory); }, function($rootScope, $exceptionHandler, $compile) { $compile('<div attr="before {{error.throw()}} after"></div>', null, true)($rootScope); var errorLogs = $exceptionHandler.errors; @@ -387,8 +387,8 @@ describe('Binder', function() { })); it('ActionOnAHrefThrowsError', inject( - function(service){ - service('$exceptionHandler', $exceptionHandlerMockFactory); + function($provide){ + $provide.factory('$exceptionHandler', $exceptionHandlerMockFactory); }, function($rootScope, $exceptionHandler, $compile) { var input = $compile('<a ng:click="action()">Add Phone</a>')($rootScope); @@ -471,8 +471,8 @@ describe('Binder', function() { })); it('ItShouldDisplayErrorWhenActionIsSyntacticlyIncorrect', inject( - function(service){ - service('$exceptionHandler', $exceptionHandlerMockFactory); + function($provide){ + $provide.factory('$exceptionHandler', $exceptionHandlerMockFactory); }, function($rootScope, $exceptionHandler, $log, $compile) { var element = $compile( diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js index 8c36677d..3ba819b8 100644 --- a/test/InjectorSpec.js +++ b/test/InjectorSpec.js @@ -4,10 +4,12 @@ describe('injector', function() { var providers; var injector; - beforeEach(function() { - providers = extensionMap({}, 'providers'); - injector = createInjector(providers); - }); + beforeEach(inject(function($injector, $provide) { + providers = function(name, factory, decoration){ + $provide.factory(name, extend(factory, decoration||{})); + }; + injector = $injector; + })); it("should return same instance from calling provider", function() { var instance = {}, @@ -29,10 +31,10 @@ describe('injector', function() { it('should resolve dependency graph and instantiate all services just once', function() { var log = []; -// s1 -// / |\ -// / s2\ -// / / | \\ +// s1 +// / | \ +// / s2 \ +// / / | \ \ // /s3 < s4 > s5 // // // s6 @@ -58,15 +60,24 @@ describe('injector', function() { }); it('should proved path to the missing provider', function() { + providers('a', function(idontexist) {return 1;}); + providers('b', function(a) {return 2;}); expect(function() { - injector('idontexist', ['a', 'b']); + injector('b'); }).toThrow("Unknown provider for 'idontexist' <- 'a' <- 'b'."); }); it('should autostart eager services', function() { var log = ''; - providers('eager', function() {log += 'eager;'; return 'foo';}, {$eager: true}); - injector = createInjector(providers); + injector = createInjector([function($provide){ + $provide.service('eager', function() { + this.$eager = true; + this.$get = function(){ + log += 'eager;'; + return 'foo'; + }; + }); + }]); expect(log).toEqual('eager;'); expect(injector('eager')).toBe('foo'); }); @@ -88,20 +99,22 @@ describe('injector', function() { it('should call function', function() { - fn.$inject = ['a', 'b']; - injector.invoke({name:"this"}, fn, [3, 4]); + fn.$inject = ['a', 'b', 'c', 'd']; + injector.invoke({name:"this"}, fn, {c:3, d: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]); + injector.invoke({name:"this"}, ['a', 'b', 'c', 'd', fn], {c:3, d:4}); expect(args).toEqual([{name:'this'}, 1, 2, 3, 4]); }); it('should invoke the passed in function with all of the dependencies as arguments', function(){ - expect(injector(['a', 'b', fn], [3, 4])).toEqual(10); + providers('c', function() {return 3;}); + providers('d', function() {return 4;}); + expect(injector(['a', 'b', 'c', 'd', fn])).toEqual(10); }); @@ -159,38 +172,17 @@ describe('injector', function() { }).toThrow(); }); - it('should infer injection on services', function() { - var $injector = createInjector({ - a: function() { return 'a';}, - b: function(a) { return a + 'b';} - }); - expect($injector('b')).toEqual('ab'); - }); - }); - - 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() { - expect(annotate(['a'], {}).$inject).toEqual(['a']); - expect(annotate(['a', 'b'], {}).$inject).toEqual(['a', 'b']); - }); }); -}); -describe('injector2', function() { it('should have $injector', function() { - var $injector = createInjector2(); + var $injector = createInjector(); expect($injector('$injector')).toBe($injector); }); it('should define module', function() { var log = ''; - var injector = createInjector2([function($provide) { + var injector = createInjector([function($provide) { $provide.value('value', 'value;'); $provide.factory('fn', valueFn('function;')); $provide.service('service', function() { @@ -208,7 +200,7 @@ describe('injector2', function() { describe('module', function() { it('should provide $injector and $provide even when no module is requested', function() { var $provide, - $injector = createInjector2([ + $injector = createInjector([ angular.extend(function(p) { $provide = p; }, {$inject: ['$provide']}) ]); expect($injector('$injector')).toBe($injector); @@ -218,7 +210,7 @@ describe('injector2', function() { it('should load multiple function modules and infer inject them', function() { var a = 'junk'; - var $injector = createInjector2([ + var $injector = createInjector([ function() { a = 'A'; // reset to prove we ran }, @@ -239,7 +231,7 @@ describe('injector2', function() { it('should run symbolic modules', function() { - var $injector = createInjector2(['myModule'], { + var $injector = createInjector(['myModule'], { myModule: ['$provide', function(provide) { provide.value('a', 'abc'); }] @@ -251,7 +243,7 @@ describe('injector2', function() { describe('$provide', function() { describe('value', function(){ it('should configure $provide values', function() { - expect(createInjector2([function($provide) { + expect(createInjector([function($provide) { $provide.value('value', 'abc'); }])('value')).toEqual('abc'); }); @@ -260,7 +252,7 @@ describe('injector2', function() { describe('factory', function(){ it('should configure $provide factory function', function() { - expect(createInjector2([function($provide) { + expect(createInjector([function($provide) { $provide.factory('value', valueFn('abc')); }])('value')).toEqual('abc'); }); @@ -269,7 +261,7 @@ describe('injector2', function() { describe('service', function(){ it('should configure $provide service object', function() { - expect(createInjector2([function($provide) { + expect(createInjector([function($provide) { $provide.service('value', { $get: valueFn('abc') }); @@ -283,7 +275,7 @@ describe('injector2', function() { expect(this instanceof Type).toBe(true); return 'abc'; }; - expect(createInjector2([function($provide) { + expect(createInjector([function($provide) { $provide.service('value', Type); }])('value')).toEqual('abc'); }); @@ -294,7 +286,7 @@ describe('injector2', function() { describe('error handling', function() { it('should handle wrong argument type', function() { expect(function() { - createInjector2([ + createInjector([ {} ], {}); }).toThrow("Argument 'module' is not a function, got Object"); @@ -303,7 +295,7 @@ describe('injector2', function() { it('should handle exceptions', function() { expect(function() { - createInjector2([function() { + createInjector([function() { throw 'MyError'; }], {}); }).toThrow('MyError'); @@ -312,7 +304,7 @@ describe('injector2', function() { it('should handle no module alias', function() { expect(function() { - createInjector2([function(dontExist) { + createInjector([function(dontExist) { }], {}); }).toThrow("Unknown provider for 'dontExist'."); }); @@ -326,7 +318,7 @@ describe('injector2', function() { $provide; beforeEach(function() { - $injector = createInjector2([ ['$provide', function(provide) { + $injector = createInjector([ ['$provide', function(provide) { ($provide = provide).value('instance', instance = {name:'angular'}); }]]); }); @@ -350,7 +342,7 @@ describe('injector2', function() { var $injector; beforeEach(function() { - $injector = createInjector2([ function($provide) { + $injector = createInjector([ function($provide) { $provide.value('book', 'moby'); $provide.value('author', 'melville'); }]); @@ -365,6 +357,16 @@ describe('injector2', function() { }); + it('should invoke method with locals', function() { + expect($injector(function(book, author) { return author + ':' + book;})).toEqual('melville:moby'); + expect($injector.invoke($injector, + function(book, author, chapter) { + expect(this).toEqual($injector); + return author + ':' + book + '-' + chapter; + }, {author:'m', chapter:'ch1'})).toEqual('m:moby-ch1'); + }); + + it('should invoke method which is annotated', function() { expect($injector(extend(function(b, a) { return a + ':' + b}, {$inject:['book', 'author']}))). toEqual('melville:moby'); @@ -395,7 +397,7 @@ describe('injector2', function() { var $injector; beforeEach(function() { - $injector = createInjector2([ function($provide) { + $injector = createInjector([ function($provide) { $provide.value('book', 'moby'); $provide.value('author', 'melville'); }]); @@ -433,7 +435,19 @@ describe('injector2', function() { }); }); - describe('injector chaining', function() { - + describe('$eager', function(){ + it('should eagerly instantiate a service if $eager is true', function() { + var log = []; + createInjector([function($provide){ + $provide.service('svc1', function() { + this.$get = function(){ + log.push('svc1'); + } + this.$eager = true; + }); + }]); + expect(log).toEqual(['svc1']); + }); }); + }); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 928b4f6c..f648eb1b 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -4,9 +4,9 @@ describe("resource", function() { var resource, CreditCard, callback; beforeEach(inject( - function(service) { - service('$xhr.error', function(){return jasmine.createSpy('xhr.error')}); - service.alias('$xhr.error', '$xhrError'); + function($provide) { + $provide.value('$xhr.error', jasmine.createSpy('xhr.error')); + $provide.factory('$xhrError', ['$xhr.error', identity]); }, function($xhr) { resource = new ResourceFactory($xhr); diff --git a/test/markupSpec.js b/test/markupSpec.js index c23cc62d..f93acb98 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -150,7 +150,7 @@ describe("markups", function() { it('should bind Text with no Bindings', inject(function($compile) { var $rootScope; function newScope (){ - return $rootScope = angular.injector()('$rootScope'); + return $rootScope = angular.injector('NG')('$rootScope'); } forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { var element = $compile('<div ng:' + name + '="some"></div>')(newScope()) diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index 6ecc386d..411320e8 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -10,7 +10,7 @@ describe("angular.scenario.dsl", function() { document: _jQuery("<div></div>"), angular: new angular.scenario.testing.MockAngular() }; - $root = angular.injector()('$rootScope'); + $root = angular.injector('NG')('$rootScope'); $root.emit = function(eventName) { eventLog.push(eventName); }; diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js index 4e0dbed6..ccf70aaf 100644 --- a/test/service/compilerSpec.js +++ b/test/service/compilerSpec.js @@ -3,7 +3,7 @@ describe('compiler', function() { var compiler, textMmarkup, attrMarkup, directives, widgets, compile, log, $rootScope; - beforeEach(inject(function(service){ + beforeEach(inject(function($provide){ textMmarkup = []; attrMarkup = []; widgets = extensionMap({}, 'widget'); @@ -26,10 +26,10 @@ describe('compiler', function() { }; log = ""; - service('$textMarkup', valueFn(textMmarkup)); - service('$attrMarkup', valueFn(attrMarkup)); - service('$directive', valueFn(directives)); - service('$widget', valueFn(widgets)); + $provide.value('$textMarkup', textMmarkup); + $provide.value('$attrMarkup', attrMarkup); + $provide.value('$directive', directives); + $provide.value('$widget', widgets); })); diff --git a/test/service/cookiesSpec.js b/test/service/cookiesSpec.js index 2569645b..66bdc504 100644 --- a/test/service/cookiesSpec.js +++ b/test/service/cookiesSpec.js @@ -1,8 +1,8 @@ 'use strict'; describe('$cookies', function() { - beforeEach(inject(function(service) { - service('$browser', function(){ + beforeEach(inject(function($provide) { + $provide.factory('$browser', function(){ return angular.extend(new MockBrowser(), {cookieHash: {preexisting:'oldCookie'}}); }); })); diff --git a/test/service/deferSpec.js b/test/service/deferSpec.js index 98ddeac5..2468512d 100644 --- a/test/service/deferSpec.js +++ b/test/service/deferSpec.js @@ -1,8 +1,8 @@ 'use strict'; describe('$defer', function() { - beforeEach(inject(function(service) { - service('$exceptionHandler', function(){ + beforeEach(inject(function($provide) { + $provide.factory('$exceptionHandler', function(){ return jasmine.createSpy('$exceptionHandler'); }); })); diff --git a/test/service/exceptionHandlerSpec.js b/test/service/exceptionHandlerSpec.js index 3bfb70c0..821ad7b8 100644 --- a/test/service/exceptionHandlerSpec.js +++ b/test/service/exceptionHandlerSpec.js @@ -4,9 +4,9 @@ describe('$exceptionHandler', function() { it('should log errors', inject( - function(service){ - service('$exceptionHandler', $exceptionHandlerFactory); - service('$log', valueFn($logMock)); + function($provide){ + $provide.factory('$exceptionHandler', $exceptionHandlerFactory); + $provide.value('$log', $logMock); }, function($log, $exceptionHandler) { $log.error.rethrow = false; diff --git a/test/service/locationSpec.js b/test/service/locationSpec.js index 38df2619..65ca36a7 100644 --- a/test/service/locationSpec.js +++ b/test/service/locationSpec.js @@ -308,13 +308,9 @@ describe('$location', function() { function initService(html5Mode, hashPrefix, supportHistory) { - return function(service){ - service('$locationConfig', function(){ - return {html5Mode: html5Mode, hashPrefix: hashPrefix}; - }); - service('$sniffer', function(){ - return {history: supportHistory}; - }); + return function($provide){ + $provide.value('$locationConfig', {html5Mode: html5Mode, hashPrefix: hashPrefix}); + $provide.value('$sniffer', {history: supportHistory}); }; } function initBrowser(url, basePath) { @@ -580,7 +576,7 @@ describe('$location', function() { var root, link, originalBrowser, lastEventPreventDefault; function configureService(linkHref, html5Mode, supportHist, attrs, content) { - return function(service){ + return function($provide){ var jqRoot = jqLite('<div></div>'); attrs = attrs ? ' ' + attrs + ' ' : ''; link = jqLite('<a href="' + linkHref + '"' + attrs + '>' + content + '</a>')[0]; @@ -588,9 +584,9 @@ describe('$location', function() { jqLite(document.body).append(jqRoot); - service('$document', function(){ return jqRoot; }); - service('$sniffer', function(){ return {history: supportHist}; }); - service('$locationConfig', function(){ return {html5Mode: html5Mode, hashPrefix: '!'}; }); + $provide.value('$document', jqRoot); + $provide.value('$sniffer', {history: supportHist}); + $provide.value('$locationConfig', {html5Mode: html5Mode, hashPrefix: '!'}); }; } diff --git a/test/service/logSpec.js b/test/service/logSpec.js index 8c56d99e..3b860756 100644 --- a/test/service/logSpec.js +++ b/test/service/logSpec.js @@ -9,12 +9,12 @@ describe('$log', function() { function info() { logger+= 'info;'; } function error() { logger+= 'error;'; } - beforeEach(inject(function(service){ + beforeEach(inject(function($provide){ $window = {}; logger = ''; - service('$log', $logFactory); - service('$exceptionHandler', valueFn(rethrow)); - service('$window', valueFn($window)); + $provide.factory('$log', $logFactory); + $provide.value('$exceptionHandler', rethrow); + $provide.value('$window', $window); })); it('should use console if present', inject( diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index 2cd2f635..b7f50edb 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -2,8 +2,8 @@ describe('Scope', function() { - beforeEach(inject(function(service) { - service('$exceptionHandler', $exceptionHandlerMockFactory); + beforeEach(inject(function($provide) { + $provide.factory('$exceptionHandler', $exceptionHandlerMockFactory); })); @@ -66,7 +66,7 @@ describe('Scope', function() { this.callCount = 0; this.name = name; } - Cntl.$inject = ['$browser']; + Cntl.$inject = ['$browser', 'name']; Cntl.prototype = { myFn: function() { @@ -75,7 +75,7 @@ describe('Scope', function() { } }; - var cntl = $rootScope.$new(Cntl, ['misko']); + var cntl = $rootScope.$new(Cntl, {name:'misko'}); expect($rootScope.$browser).toBeUndefined(); expect($rootScope.myFn).toBeUndefined(); @@ -285,7 +285,7 @@ describe('Scope', function() { it('should return a function that allows listeners to be unregistered', inject(function($rootScope) { - var root = angular.injector()('$rootScope'), + var root = angular.injector('NG')('$rootScope'), listener = jasmine.createSpy('watch listener'), listenerRemove; @@ -470,7 +470,7 @@ describe('Scope', function() { it('should add listener for both $emit and $broadcast events', inject(function($rootScope) { var log = '', - root = angular.injector()('$rootScope'), + root = angular.injector('NG')('$rootScope'), child = root.$new(); function eventFn() { @@ -490,7 +490,7 @@ describe('Scope', function() { it('should return a function that deregisters the listener', inject(function($rootScope) { var log = '', - root = angular.injector()('$rootScope'), + root = angular.injector('NG')('$rootScope'), child = root.$new(), listenerRemove; @@ -669,7 +669,7 @@ describe('Scope', function() { describe('listener', function() { it('should receive event object', inject(function($rootScope) { - var scope = angular.injector()('$rootScope'), + var scope = angular.injector('NG')('$rootScope'), child = scope.$new(), event; @@ -685,7 +685,7 @@ describe('Scope', function() { it('should support passing messages as varargs', inject(function($rootScope) { - var scope = angular.injector()('$rootScope'), + var scope = angular.injector('NG')('$rootScope'), child = scope.$new(), args; diff --git a/test/service/xhr.bulkSpec.js b/test/service/xhr.bulkSpec.js index 6f273f64..6e55b387 100644 --- a/test/service/xhr.bulkSpec.js +++ b/test/service/xhr.bulkSpec.js @@ -3,12 +3,10 @@ describe('$xhr.bulk', function() { var log; - beforeEach(inject(function(service) { - service('$xhr.error', function(){ - return jasmine.createSpy('$xhr.error'); - }); - service.alias('$xhr.error', '$xhrError'); - service.alias('$xhr.bulk', '$xhrBulk'); + beforeEach(inject(function($provide) { + $provide.value('$xhr.error', jasmine.createSpy('$xhr.error')); + $provide.factory('$xhrError', ['$xhr.error', identity]); + $provide.factory('$xhrBulk', ['$xhr.bulk', identity]); log = ''; })); diff --git a/test/service/xhr.cacheSpec.js b/test/service/xhr.cacheSpec.js index 328dfe3a..b6eeb6aa 100644 --- a/test/service/xhr.cacheSpec.js +++ b/test/service/xhr.cacheSpec.js @@ -3,13 +3,11 @@ describe('$xhr.cache', function() { var log; - beforeEach(inject(function(service) { - service('$xhr.error', function(){ - return jasmine.createSpy('$xhr.error'); - }); - service.alias('$xhr.cache', '$xhrCache'); - service.alias('$xhr.bulk', '$xhrBulk'); - service.alias('$xhr.error', '$xhrError'); + beforeEach(inject(function($provide) { + $provide.value('$xhr.error', jasmine.createSpy('$xhr.error')); + $provide.factory('$xhrError', ['$xhr.error', identity]); + $provide.factory('$xhrBulk', ['$xhr.bulk', identity]); + $provide.factory('$xhrCache', ['$xhr.cache', identity]); log = ''; })); diff --git a/test/service/xhr.errorSpec.js b/test/service/xhr.errorSpec.js index 0ed5ab59..f9ce2b72 100644 --- a/test/service/xhr.errorSpec.js +++ b/test/service/xhr.errorSpec.js @@ -3,11 +3,9 @@ describe('$xhr.error', function() { var log; - beforeEach(inject(function(service) { - service('$xhr.error', function(){ - return jasmine.createSpy('$xhr.error'); - }); - service.alias('$xhr.error', '$xhrError'); + beforeEach(inject(function($provide) { + $provide.value('$xhr.error', jasmine.createSpy('$xhr.error')); + $provide.factory('$xhrError', ['$xhr.error', identity]); log = ''; })); diff --git a/test/service/xhrSpec.js b/test/service/xhrSpec.js index 997994d7..83c5f93f 100644 --- a/test/service/xhrSpec.js +++ b/test/service/xhrSpec.js @@ -4,12 +4,10 @@ describe('$xhr', function() { var log; - beforeEach(inject(function(service) { + beforeEach(inject(function($provide) { log = ''; - service('$xhr.error', function(){ - return jasmine.createSpy('xhr.error'); - }); - service.alias('$xhr.error', '$xhrError'); + $provide.value('$xhr.error', jasmine.createSpy('xhr.error')); + $provide.factory('$xhrError', ['$xhr.error', identity]); })); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 3e68fbed..eb98cb6f 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -88,33 +88,9 @@ function inject(){ var blockFns = sliceArgs(arguments); return function(){ var spec = this; + spec.$injector = spec.$injector || angular.injector('NG'); angular.forEach(blockFns, function(fn){ - fn.$inject = inferInjectionArgs(fn); - if (equals(fn.$inject, [])) { - fn.apply(spec); - } else if (equals(fn.$inject, ['service'])) { - if (spec.$injector) { - throw Error('$injector already created for this test'); - } - if (!spec.$service) { - spec.$service = function(name, fn) { - if (fn) { spec.$service[name] = fn; } - return spec.$service[name]; - } - spec.$service.alias = function (name, alias) { - spec.$service(alias, extend(function(x){ return x; }, {$inject:[name]})); - }; - forEach(angularService, function(value, key){ - spec.$service(key, value); - }); - } - fn.call(spec, spec.$service); - } else { - if (!spec.$injector) { - spec.$injector = angular.injector(spec.$service || angular.service); - } - spec.$injector.invoke(spec, fn); - } + spec.$injector.invoke(spec, fn); }); }; } diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index 6ab53ab0..8d409b25 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -460,12 +460,12 @@ describe('widget: input', function() { describe('scope declaration', function() { it('should read the declaration from scope', inject(function($rootScope, $compile) { var input, $formFactory; - element = angular.element('<input type="@MyType" ng:model="abc">'); + var element = angular.element('<input type="@MyType" ng:model="abc">'); $rootScope.MyType = function($f, i) { input = i; $formFactory = $f; }; - $rootScope.MyType.$inject = ['$formFactory']; + $rootScope.MyType.$inject = ['$formFactory', '$element']; $compile(element)($rootScope); @@ -475,7 +475,7 @@ describe('widget: input', function() { it('should throw an error of Controller not declared in scope', inject(function($rootScope, $compile) { var input, $formFactory; - element = angular.element('<input type="@DontExist" ng:model="abc">'); + var element = angular.element('<input type="@DontExist" ng:model="abc">'); var error; try { $compile(element)($rootScope); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index b7ef16a4..ef28ea77 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -487,7 +487,7 @@ describe("widget", function() { })); it('should be possible to nest ng:view in ng:include', inject(function() { - var injector = createInjector(angularService); + var injector = angular.injector('NG'); var myApp = injector('$rootScope'); var $browser = myApp.$service('$browser'); $browser.xhr.expectGET('includePartial.html').respond('view: <ng:view></ng:view>'); |
