diff options
| author | Misko Hevery | 2011-10-17 16:56:56 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-11-14 16:39:31 -0800 |
| commit | 48697a2b86dbb12ea8de64cc5fece7caf68b321e (patch) | |
| tree | 1fa50659f0bb5de2640dea2a2e5bb5628f2bb14a /test/widget/inputSpec.js | |
| parent | 93b777c916ccff243c5a6080bf5f39860ac7bf39 (diff) | |
| download | angular.js-48697a2b86dbb12ea8de64cc5fece7caf68b321e.tar.bz2 | |
refactor(injector): turn scope into a service
- turn scope into a $rootScope service.
- injector is now a starting point for creating angular application.
- added inject() method which wraps jasmine its/beforeEach/afterEach,
and which allows configuration and injection of services.
- refactor tests to use inject() where possible
BREAK:
- removed angular.scope() method
Diffstat (limited to 'test/widget/inputSpec.js')
| -rw-r--r-- | test/widget/inputSpec.js | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index 179f8156..a889212f 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -4,8 +4,8 @@ describe('widget: input', function() { var compile = null, element = null, scope = null, defer = null; var doc = null; - beforeEach(function() { - scope = null; + beforeEach(inject(function($rootScope) { + scope = $rootScope; element = null; compile = function(html, parent) { if (parent) { @@ -14,12 +14,12 @@ describe('widget: input', function() { } else { element = jqLite(html); } - scope = angular.compile(element)(); + angular.compile(element)(scope); scope.$apply(); defer = scope.$service('$browser').defer; return scope; }; - }); + })); afterEach(function() { dealoc(element); @@ -28,8 +28,7 @@ describe('widget: input', function() { describe('text', function() { - var scope = null, - form = null, + var form = null, formElement = null, inputElement = null; @@ -41,7 +40,7 @@ describe('widget: input', function() { formElement = doc = angular.element('<form name="form"><input ' + prefix + 'type="text" ng:model="name" name="name" ng:change="change()"></form>'); inputElement = formElement.find('input'); - scope = angular.compile(doc)(); + angular.compile(doc)(scope); form = formElement.inheritedData('$form'); }; @@ -91,18 +90,18 @@ describe('widget: input', function() { }); - it('should change non-html5 types to text', function() { + it('should change non-html5 types to text', inject(function($rootScope) { doc = angular.element('<form name="form"><input type="abc" ng:model="name"></form>'); - scope = angular.compile(doc)(); + angular.compile(doc)($rootScope); expect(doc.find('input').attr('type')).toEqual('text'); - }); + })); - it('should not change html5 types to text', function() { + it('should not change html5 types to text', inject(function($rootScope) { doc = angular.element('<form name="form"><input type="number" ng:model="name"></form>'); - scope = angular.compile(doc)(); + angular.compile(doc)($rootScope); expect(doc.find('input')[0].getAttribute('type')).toEqual('number'); - }); + })); }); @@ -455,35 +454,33 @@ describe('widget: input', function() { describe('scope declaration', function() { - it('should read the declaration from scope', function() { + it('should read the declaration from scope', inject(function($rootScope) { var input, $formFactory; element = angular.element('<input type="@MyType" ng:model="abc">'); - scope = angular.scope(); - scope.MyType = function($f, i) { + $rootScope.MyType = function($f, i) { input = i; $formFactory = $f; }; - scope.MyType.$inject = ['$formFactory']; + $rootScope.MyType.$inject = ['$formFactory']; - angular.compile(element)(scope); + angular.compile(element)($rootScope); - expect($formFactory).toBe(scope.$service('$formFactory')); + expect($formFactory).toBe($rootScope.$service('$formFactory')); expect(input[0]).toBe(element[0]); - }); + })); - it('should throw an error of Cntoroller not declared in scope', function() { + it('should throw an error of Controller not declared in scope', inject(function($rootScope) { var input, $formFactory; element = angular.element('<input type="@DontExist" ng:model="abc">'); var error; try { - scope = angular.scope(); - angular.compile(element)(scope); + angular.compile(element)($rootScope); error = 'no error thrown'; } catch (e) { error = e; } expect(error.message).toEqual("Argument 'DontExist' is not a function, got undefined"); - }); + })); }); @@ -580,16 +577,16 @@ describe('widget: input', function() { {'ng:maxlength': 3}); - it('should throw an error when scope pattern can\'t be found', function() { - var el = jqLite('<input ng:model="foo" ng:pattern="fooRegexp">'), - scope = angular.compile(el)(); + it('should throw an error when scope pattern can\'t be found', inject(function($rootScope) { + var el = jqLite('<input ng:model="foo" ng:pattern="fooRegexp">'); + angular.compile(el)($rootScope); el.val('xx'); browserTrigger(el, 'keydown'); - expect(function() { scope.$service('$browser').defer.flush(); }). + expect(function() { $rootScope.$service('$browser').defer.flush(); }). toThrow('Expected fooRegexp to be a RegExp but was undefined'); dealoc(el); - }); + })); }); }); |
