From d12df0d360fe0dabdca3591654327834bee2803b Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 25 Oct 2011 22:21:21 -0700 Subject: refactor(compiler) turn compiler into a service BREAK - remove angular.compile() since the compile method is now a service and needs to be injected --- test/widget/formSpec.js | 24 ++++++++++++------------ test/widget/inputSpec.js | 30 +++++++++++++++++------------- test/widget/selectSpec.js | 4 ++-- 3 files changed, 31 insertions(+), 27 deletions(-) (limited to 'test/widget') diff --git a/test/widget/formSpec.js b/test/widget/formSpec.js index a30f21eb..7a92dbf4 100644 --- a/test/widget/formSpec.js +++ b/test/widget/formSpec.js @@ -8,17 +8,17 @@ describe('form', function() { }); - it('should attach form to DOM', inject(function($rootScope) { + it('should attach form to DOM', inject(function($rootScope, $compile) { doc = angular.element('
'); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); expect(doc.data('$form')).toBeTruthy(); })); - it('should prevent form submission', inject(function($rootScope) { + it('should prevent form submission', inject(function($rootScope, $compile) { var startingUrl = '' + window.location; doc = angular.element(''); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); browserTrigger(doc.find('input')); waitsFor( function() { return true; }, @@ -29,18 +29,18 @@ describe('form', function() { })); - it('should publish form to scope', inject(function($rootScope) { + it('should publish form to scope', inject(function($rootScope, $compile) { doc = angular.element('
'); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); expect($rootScope.myForm).toBeTruthy(); expect(doc.data('$form')).toBeTruthy(); expect(doc.data('$form')).toEqual($rootScope.myForm); })); - it('should have ng-valide/ng-invalid style', inject(function($rootScope) { + it('should have ng-valide/ng-invalid style', inject(function($rootScope, $compile) { doc = angular.element('
'); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); $rootScope.text = 'misko'; $rootScope.$digest(); @@ -54,14 +54,14 @@ describe('form', function() { })); - it('should chain nested forms', inject(function($rootScope) { + it('should chain nested forms', inject(function($rootScope, $compile) { doc = angular.element( '' + '' + '' + '' + ''); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); var parent = $rootScope.parent; var child = $rootScope.child; var input = child.text; @@ -76,14 +76,14 @@ describe('form', function() { })); - it('should chain nested forms in repeater', inject(function($rootScope) { + it('should chain nested forms in repeater', inject(function($rootScope, $compile) { doc = angular.element( '' + '' + '' + '' + ''); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); $rootScope.forms = [1]; $rootScope.$digest(); diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js index a889212f..6ab53ab0 100644 --- a/test/widget/inputSpec.js +++ b/test/widget/inputSpec.js @@ -2,10 +2,12 @@ describe('widget: input', function() { var compile = null, element = null, scope = null, defer = null; + var $compile = null; var doc = null; - beforeEach(inject(function($rootScope) { + beforeEach(inject(function($rootScope, $compile) { scope = $rootScope; + set$compile($compile); element = null; compile = function(html, parent) { if (parent) { @@ -14,13 +16,15 @@ describe('widget: input', function() { } else { element = jqLite(html); } - angular.compile(element)(scope); + $compile(element)(scope); scope.$apply(); defer = scope.$service('$browser').defer; return scope; }; })); + function set$compile(c) { $compile = c; } + afterEach(function() { dealoc(element); dealoc(doc); @@ -40,7 +44,7 @@ describe('widget: input', function() { formElement = doc = angular.element('
'); inputElement = formElement.find('input'); - angular.compile(doc)(scope); + $compile(doc)(scope); form = formElement.inheritedData('$form'); }; @@ -90,16 +94,16 @@ describe('widget: input', function() { }); - it('should change non-html5 types to text', inject(function($rootScope) { + it('should change non-html5 types to text', inject(function($rootScope, $compile) { doc = angular.element('
'); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); expect(doc.find('input').attr('type')).toEqual('text'); })); - it('should not change html5 types to text', inject(function($rootScope) { + it('should not change html5 types to text', inject(function($rootScope, $compile) { doc = angular.element('
'); - angular.compile(doc)($rootScope); + $compile(doc)($rootScope); expect(doc.find('input')[0].getAttribute('type')).toEqual('number'); })); }); @@ -454,7 +458,7 @@ describe('widget: input', function() { describe('scope declaration', function() { - it('should read the declaration from scope', inject(function($rootScope) { + it('should read the declaration from scope', inject(function($rootScope, $compile) { var input, $formFactory; element = angular.element(''); $rootScope.MyType = function($f, i) { @@ -463,18 +467,18 @@ describe('widget: input', function() { }; $rootScope.MyType.$inject = ['$formFactory']; - angular.compile(element)($rootScope); + $compile(element)($rootScope); expect($formFactory).toBe($rootScope.$service('$formFactory')); expect(input[0]).toBe(element[0]); })); - it('should throw an error of Controller not declared in scope', inject(function($rootScope) { + it('should throw an error of Controller not declared in scope', inject(function($rootScope, $compile) { var input, $formFactory; element = angular.element(''); var error; try { - angular.compile(element)($rootScope); + $compile(element)($rootScope); error = 'no error thrown'; } catch (e) { error = e; @@ -577,9 +581,9 @@ describe('widget: input', function() { {'ng:maxlength': 3}); - it('should throw an error when scope pattern can\'t be found', inject(function($rootScope) { + it('should throw an error when scope pattern can\'t be found', inject(function($rootScope, $compile) { var el = jqLite(''); - angular.compile(el)($rootScope); + $compile(el)($rootScope); el.val('xx'); browserTrigger(el, 'keydown'); diff --git a/test/widget/selectSpec.js b/test/widget/selectSpec.js index 31e5223d..5d92e674 100644 --- a/test/widget/selectSpec.js +++ b/test/widget/selectSpec.js @@ -3,7 +3,7 @@ describe('select', function() { var compile = null, element = null, scope = null; - beforeEach(inject(function($rootScope) { + beforeEach(inject(function($compile, $rootScope) { scope = $rootScope; element = null; compile = function(html, parent) { @@ -13,7 +13,7 @@ describe('select', function() { } else { element = jqLite(html); } - angular.compile(element)($rootScope); + $compile(element)($rootScope); scope.$apply(); return scope; }; -- cgit v1.2.3