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/AngularSpec.js | 22 +++--- test/BinderSpec.js | 146 ++++++++++++++++++------------------- test/ResourceSpec.js | 8 +-- test/ScenarioSpec.js | 12 ++-- test/directivesSpec.js | 168 +++++++++++++++++++++---------------------- test/markupSpec.js | 88 +++++++++++------------ test/service/compilerSpec.js | 140 ++++++++++++++++++------------------ test/testabilityPatch.js | 1 - test/widget/formSpec.js | 24 +++---- test/widget/inputSpec.js | 30 ++++---- test/widget/selectSpec.js | 4 +- test/widgetsSpec.js | 140 ++++++++++++++++++------------------ 12 files changed, 392 insertions(+), 391 deletions(-) (limited to 'test') diff --git a/test/AngularSpec.js b/test/AngularSpec.js index eb64a825..7e6f35fa 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -423,7 +423,7 @@ describe('angular', function() { describe('directive', function() { - it('should register directives with case-insensitive id', function() { + it('should register directives with case-insensitive id', inject(function($compile) { angularDirective('ALLCAPS', function(val, el) {el.text('+' + val + '+')}); angularDirective('lowercase', function(val, el) {el.text('-' + val + '-')}); @@ -433,14 +433,14 @@ describe('angular', function() { '' + 'xx4' + ''); - compile(el); + $compile(el); expect(lowercase(sortedHtml(el))).toBe('
' + '+xx1+' + '+xx2+' + '+xx3+' + '-xx4-' + '
'); - }); + })); }); @@ -458,25 +458,25 @@ describe('angular', function() { }); describe('compile', function() { - it('should link to existing node and create scope', inject(function($rootScope) { + it('should link to existing node and create scope', inject(function($rootScope, $compile) { var template = angular.element('
{{greeting = "hello world"}}
'); - angular.compile(template)($rootScope); + $compile(template)($rootScope); $rootScope.$digest(); expect(template.text()).toEqual('hello world'); expect($rootScope.greeting).toEqual('hello world'); })); - it('should link to existing node and given scope', inject(function($rootScope) { + it('should link to existing node and given scope', inject(function($rootScope, $compile) { var template = angular.element('
{{greeting = "hello world"}}
'); - angular.compile(template)($rootScope); + $compile(template)($rootScope); $rootScope.$digest(); expect(template.text()).toEqual('hello world'); })); - it('should link to new node and given scope', inject(function($rootScope) { + it('should link to new node and given scope', inject(function($rootScope, $compile) { var template = jqLite('
{{greeting = "hello world"}}
'); - var templateFn = angular.compile(template); + var templateFn = $compile(template); var templateClone = template.clone(); var element = templateFn($rootScope, function(clone){ @@ -490,9 +490,9 @@ describe('angular', function() { expect($rootScope.greeting).toEqual('hello world'); })); - it('should link to cloned node and create scope', inject(function($rootScope) { + it('should link to cloned node and create scope', inject(function($rootScope, $compile) { var template = jqLite('
{{greeting = "hello world"}}
'); - var element = angular.compile(template)($rootScope, noop); + var element = $compile(template)($rootScope, noop); $rootScope.$digest(); expect(template.text()).toEqual(''); expect(element.text()).toEqual('hello world'); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index 8938bd13..6a459074 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -4,9 +4,9 @@ describe('Binder', function() { beforeEach(function() { this.compileToHtml = function (content) { var html; - inject(function($rootScope){ + inject(function($rootScope, $compile){ content = jqLite(content); - angular.compile(content)($rootScope); + $compile(content)($rootScope); html = sortedHtml(content); }).call(this); return html; @@ -19,25 +19,25 @@ describe('Binder', function() { } }); - it('BindUpdate', inject(function($rootScope) { - angular.compile('
')($rootScope); + it('BindUpdate', inject(function($rootScope, $compile) { + $compile('
')($rootScope); $rootScope.$digest(); assertEquals(123, $rootScope.a); })); - it('ExecuteInitialization', inject(function($rootScope) { - angular.compile('
')($rootScope); + it('ExecuteInitialization', inject(function($rootScope, $compile) { + $compile('
')($rootScope); assertEquals($rootScope.a, 123); })); - it('ExecuteInitializationStatements', inject(function($rootScope) { - angular.compile('
')($rootScope); + it('ExecuteInitializationStatements', inject(function($rootScope, $compile) { + $compile('
')($rootScope); assertEquals($rootScope.a, 123); assertEquals($rootScope.b, 345); })); - it('ApplyTextBindings', inject(function($rootScope) { - var element = angular.compile('
x
')($rootScope); + it('ApplyTextBindings', inject(function($rootScope, $compile) { + var element = $compile('
x
')($rootScope); $rootScope.model = {a:123}; $rootScope.$apply(); assertEquals('123', element.text()); @@ -51,7 +51,7 @@ describe('Binder', function() { assertEquals(this.compileToHtml("{{b}}"), ''); }); - it('BindingSpaceConfusesIE', inject(function($rootScope) { + it('BindingSpaceConfusesIE', inject(function($rootScope, $compile) { if (!msie) return; var span = document.createElement("span"); span.innerHTML = ' '; @@ -65,44 +65,44 @@ describe('Binder', function() { this.compileToHtml("{{A}} x {{B}} ({{C}})")); })); - it('BindingOfAttributes', inject(function($rootScope) { - var element = angular.compile("")($rootScope); + it('BindingOfAttributes', inject(function($rootScope, $compile) { + var element = $compile("")($rootScope); var attrbinding = element.attr("ng:bind-attr"); var bindings = fromJson(attrbinding); assertEquals("http://s/a{{b}}c", decodeURI(bindings.href)); assertTrue(!bindings.foo); })); - it('MarkMultipleAttributes', inject(function($rootScope) { - var element = angular.compile('')($rootScope); + it('MarkMultipleAttributes', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope); var attrbinding = element.attr("ng:bind-attr"); var bindings = fromJson(attrbinding); assertEquals(bindings.foo, "{{d}}"); assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c"); })); - it('AttributesNoneBound', inject(function($rootScope) { - var a = angular.compile("")($rootScope); + it('AttributesNoneBound', inject(function($rootScope, $compile) { + var a = $compile("")($rootScope); assertEquals(a[0].nodeName, "A"); assertTrue(!a.attr("ng:bind-attr")); })); - it('ExistingAttrbindingIsAppended', inject(function($rootScope) { - var a = angular.compile("")($rootScope); + it('ExistingAttrbindingIsAppended', inject(function($rootScope, $compile) { + var a = $compile("")($rootScope); assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr')); })); - it('AttributesAreEvaluated', inject(function($rootScope) { - var a = angular.compile('')($rootScope); + it('AttributesAreEvaluated', inject(function($rootScope, $compile) { + var a = $compile('')($rootScope); $rootScope.$eval('a=1;b=2'); $rootScope.$apply(); assertEquals(a.attr('a'), 'a'); assertEquals(a.attr('b'), 'a+b=3'); })); - it('InputTypeButtonActionExecutesInScope', inject(function($rootScope) { + it('InputTypeButtonActionExecutesInScope', inject(function($rootScope, $compile) { var savedCalled = false; - var element = angular.compile( + var element = $compile( '')($rootScope); $rootScope.person = {}; $rootScope.person.save = function() { @@ -112,9 +112,9 @@ describe('Binder', function() { assertTrue(savedCalled); })); - it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope) { + it('InputTypeButtonActionExecutesInScope2', inject(function($rootScope, $compile) { var log = ""; - var element = angular.compile('')($rootScope); + var element = $compile('')($rootScope); $rootScope.action = function() { log += 'click;'; }; @@ -123,9 +123,9 @@ describe('Binder', function() { expect(log).toEqual('click;'); })); - it('ButtonElementActionExecutesInScope', inject(function($rootScope) { + it('ButtonElementActionExecutesInScope', inject(function($rootScope, $compile) { var savedCalled = false; - var element = angular.compile('')($rootScope); + var element = $compile('')($rootScope); $rootScope.person = {}; $rootScope.person.save = function() { savedCalled = true; @@ -134,8 +134,8 @@ describe('Binder', function() { assertTrue(savedCalled); })); - it('RepeaterUpdateBindings', inject(function($rootScope) { - var form = angular.compile( + it('RepeaterUpdateBindings', inject(function($rootScope, $compile) { + var form = $compile( '
    ' + '
  • ' + '
')($rootScope); @@ -171,8 +171,8 @@ describe('Binder', function() { $rootScope.$apply(); })); - it('RepeaterContentDoesNotBind', inject(function($rootScope) { - var element = angular.compile( + it('RepeaterContentDoesNotBind', inject(function($rootScope, $compile) { + var element = $compile( '
    ' + '
  • ' + '
')($rootScope); @@ -189,8 +189,8 @@ describe('Binder', function() { assertTrue(html.indexOf('action="foo();"') > 0 ); }); - it('RepeaterAdd', inject(function($rootScope) { - var element = angular.compile('
')($rootScope); + it('RepeaterAdd', inject(function($rootScope, $compile) { + var element = $compile('
')($rootScope); $rootScope.items = [{x:'a'}, {x:'b'}]; $rootScope.$apply(); var first = childNode(element, 1); @@ -204,8 +204,8 @@ describe('Binder', function() { expect($rootScope.items[0].x).toEqual('ABC'); })); - it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope) { - var element = angular.compile('
{{i}}
')($rootScope); + it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope, $compile) { + var element = $compile('
{{i}}
')($rootScope); var items = {}; $rootScope.items = items; @@ -225,8 +225,8 @@ describe('Binder', function() { function(service){ service('$exceptionHandler', $exceptionHandlerMockFactory); }, - function($rootScope, $exceptionHandler) { - angular.compile('
{{error.throw()}}
', null, true)($rootScope); + function($rootScope, $exceptionHandler, $compile) { + $compile('
{{error.throw()}}
', null, true)($rootScope); var errorLogs = $exceptionHandler.errors; $rootScope.error = { @@ -247,8 +247,8 @@ describe('Binder', function() { it('IfAttrBindingThrowsErrorDecorateTheAttribute', inject(function(service){ service('$exceptionHandler', $exceptionHandlerMockFactory); - }, function($rootScope, $exceptionHandler) { - angular.compile('
', null, true)($rootScope); + }, function($rootScope, $exceptionHandler, $compile) { + $compile('
', null, true)($rootScope); var errorLogs = $exceptionHandler.errors; var count = 0; @@ -265,8 +265,8 @@ describe('Binder', function() { expect(errorLogs.length).toMatch(0); })); - it('NestedRepeater', inject(function($rootScope) { - var element = angular.compile( + it('NestedRepeater', inject(function($rootScope, $compile) { + var element = $compile( '
' + '
' + '
    ' + @@ -290,8 +290,8 @@ describe('Binder', function() { '
    ', sortedHtml(element)); })); - it('HideBindingExpression', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('HideBindingExpression', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.hidden = 3; $rootScope.$apply(); @@ -304,8 +304,8 @@ describe('Binder', function() { assertVisible(element); })); - it('HideBinding', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('HideBinding', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.hidden = 'true'; $rootScope.$apply(); @@ -323,8 +323,8 @@ describe('Binder', function() { assertVisible(element); })); - it('ShowBinding', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('ShowBinding', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.show = 'true'; $rootScope.$apply(); @@ -343,8 +343,8 @@ describe('Binder', function() { })); - it('BindClass', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('BindClass', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.clazz = 'testClass'; $rootScope.$apply(); @@ -357,8 +357,8 @@ describe('Binder', function() { assertEquals('
    ', sortedHtml(element)); })); - it('BindClassEvenOdd', inject(function($rootScope) { - var element = angular.compile( + it('BindClassEvenOdd', inject(function($rootScope, $compile) { + var element = $compile( '
    ' + '
    ' + '
    ')($rootScope); @@ -374,8 +374,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('BindStyle', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('BindStyle', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$eval('style={height: "10px"}'); $rootScope.$apply(); @@ -390,8 +390,8 @@ describe('Binder', function() { function(service){ service('$exceptionHandler', $exceptionHandlerMockFactory); }, - function($rootScope, $exceptionHandler) { - var input = angular.compile('Add Phone')($rootScope); + function($rootScope, $exceptionHandler, $compile) { + var input = $compile('Add Phone')($rootScope); $rootScope.action = function() { throw new Error('MyError'); }; @@ -400,8 +400,8 @@ describe('Binder', function() { }) ); - it('ShoulIgnoreVbNonBindable', inject(function($rootScope) { - var element = angular.compile( + it('ShoulIgnoreVbNonBindable', inject(function($rootScope, $compile) { + var element = $compile( "
    {{a}}" + "
    {{a}}
    " + "
    {{b}}
    " + @@ -412,8 +412,8 @@ describe('Binder', function() { assertEquals('123{{a}}{{b}}{{c}}', element.text()); })); - it('ShouldTemplateBindPreElements', inject(function ($rootScope) { - var element = angular.compile('
    Hello {{name}}!
    ')($rootScope); + it('ShouldTemplateBindPreElements', inject(function ($rootScope, $compile) { + var element = $compile('
    Hello {{name}}!
    ')($rootScope); $rootScope.name = "World"; $rootScope.$apply(); @@ -422,8 +422,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('FillInOptionValueWhenMissing', inject(function($rootScope) { - var element = angular.compile( + it('FillInOptionValueWhenMissing', inject(function($rootScope, $compile) { + var element = $compile( '' + '' + @@ -474,8 +474,8 @@ describe('Binder', function() { function(service){ service('$exceptionHandler', $exceptionHandlerMockFactory); }, - function($rootScope, $exceptionHandler, $log) { - var element = angular.compile( + function($rootScope, $exceptionHandler, $log, $compile) { + var element = $compile( '
    ' + '' + '' + @@ -494,8 +494,8 @@ describe('Binder', function() { }) ); - it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope) { - var element = angular.compile( + it('ItShouldSelectTheCorrectRadioBox', inject(function($rootScope, $compile) { + var element = $compile( '
    ' + '' + '' + @@ -516,8 +516,8 @@ describe('Binder', function() { assertEquals("male", male.val()); })); - it('ItShouldRepeatOnHashes', inject(function($rootScope) { - var element = angular.compile( + it('ItShouldRepeatOnHashes', inject(function($rootScope, $compile) { + var element = $compile( '
      ' + '
    • ' + '
    ')($rootScope); @@ -530,8 +530,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.name = ""; $rootScope.$watch("watched", "name=123"); $rootScope.watched = "change"; @@ -542,8 +542,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('ItShouldHandleMultilineBindings', inject(function($rootScope) { - var element = angular.compile('
    {{\n 1 \n + \n 2 \n}}
    ')($rootScope); + it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) { + var element = $compile('
    {{\n 1 \n + \n 2 \n}}
    ')($rootScope); $rootScope.$apply(); assertEquals("3", element.text()); })); diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 75d81a89..928b4f6c 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -221,8 +221,8 @@ describe("resource", function() { nakedExpect(visa).toEqual({id:123}); })); - it('should excersize full stack', inject(function($rootScope, $browser, $resource) { - angular.compile('
    ')($rootScope); + it('should excersize full stack', inject(function($rootScope, $browser, $resource, $compile) { + $compile('
    ')($rootScope); var Person = $resource('/Person/:id'); $browser.xhr.expectGET('/Person/123').respond('\n{\n"name":\n"misko"\n}\n'); var person = Person.get({id:123}); @@ -230,8 +230,8 @@ describe("resource", function() { expect(person.name).toEqual('misko'); })); - it('should return the same object when verifying the cache', inject(function($rootScope) { - angular.compile('
    ')($rootScope); + it('should return the same object when verifying the cache', inject(function($rootScope, $compile) { + $compile('
    ')($rootScope); var $browser = $rootScope.$service('$browser'); var $resource = $rootScope.$service('$resource'); var Person = $resource('/Person/:id', null, {query: {method:'GET', isArray: true, verifyCache: true}}); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index d33e880d..986e2121 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -2,22 +2,22 @@ describe("ScenarioSpec: Compilation", function() { describe('compilation', function() { - it("should compile dom node and return scope", inject(function($rootScope) { + it("should compile dom node and return scope", inject(function($rootScope, $compile) { var node = jqLite('
    {{b=a+1}}
    ')[0]; - angular.compile(node)($rootScope); + $compile(node)($rootScope); $rootScope.$digest(); expect($rootScope.a).toEqual(1); expect($rootScope.b).toEqual(2); })); - it("should compile jQuery node and return scope", inject(function($rootScope) { - var element = compile(jqLite('
    {{a=123}}
    '))($rootScope); + it("should compile jQuery node and return scope", inject(function($rootScope, $compile) { + var element = $compile(jqLite('
    {{a=123}}
    '))($rootScope); $rootScope.$digest(); expect(jqLite(element).text()).toEqual('123'); })); - it("should compile text node and return scope", inject(function($rootScope) { - var element = angular.compile('
    {{a=123}}
    ')($rootScope); + it("should compile text node and return scope", inject(function($rootScope, $compile) { + var element = $compile('
    {{a=123}}
    ')($rootScope); $rootScope.$digest(); expect(jqLite(element).text()).toEqual('123'); })); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index eb74d227..96d0993b 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -2,14 +2,14 @@ describe("directive", function() { - it("should ng:init", inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it("should ng:init", inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); expect($rootScope.a).toEqual(123); })); describe('ng:bind', function() { - it('should set text', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should set text', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); expect(element.text()).toEqual(''); $rootScope.a = 'misko'; $rootScope.$digest(); @@ -17,8 +17,8 @@ describe("directive", function() { expect(element.text()).toEqual('misko'); })); - it('should set text to blank if undefined', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should set text to blank if undefined', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.a = 'misko'; $rootScope.$digest(); expect(element.text()).toEqual('misko'); @@ -27,76 +27,76 @@ describe("directive", function() { expect(element.text()).toEqual(''); })); - it('should set html', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should set html', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.html = '
    hello
    '; $rootScope.$digest(); expect(lowercase(element.html())).toEqual('
    hello
    '); })); - it('should set unsafe html', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should set unsafe html', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.html = '
    hello
    '; $rootScope.$digest(); expect(lowercase(element.html())).toEqual('
    hello
    '); })); - it('should set element element', inject(function($rootScope) { + it('should set element element', inject(function($rootScope, $compile) { angularFilter.myElement = function() { return jqLite('hello'); }; - var element = angular.compile('
    ')($rootScope); + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect(lowercase(element.html())).toEqual('hello'); })); - it('should have $element set to current bind element', inject(function($rootScope) { + it('should have $element set to current bind element', inject(function($rootScope, $compile) { angularFilter.myFilter = function() { this.$element.addClass("filter"); return 'HELLO'; }; - var element = angular.compile('
    before
    after
    ')($rootScope); + var element = $compile('
    before
    after
    ')($rootScope); $rootScope.$digest(); expect(sortedHtml(element)).toEqual('
    before
    HELLO
    after
    '); })); - it('should suppress rendering of falsy values', inject(function($rootScope) { - var element = angular.compile('
    {{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}
    ')($rootScope); + it('should suppress rendering of falsy values', inject(function($rootScope, $compile) { + var element = $compile('
    {{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}
    ')($rootScope); $rootScope.$digest(); expect(element.text()).toEqual('-0false'); })); - it('should render object as JSON ignore $$', inject(function($rootScope) { - var element = angular.compile('
    {{ {key:"value", $$key:"hide"} }}
    ')($rootScope); + it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { + var element = $compile('
    {{ {key:"value", $$key:"hide"} }}
    ')($rootScope); $rootScope.$digest(); expect(fromJson(element.text())).toEqual({key:'value'}); })); }); describe('ng:bind-template', function() { - it('should ng:bind-template', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should ng:bind-template', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.name = 'Misko'; $rootScope.$digest(); expect(element.hasClass('ng-binding')).toEqual(true); expect(element.text()).toEqual('Hello Misko!'); })); - it('should have $element set to current bind element', inject(function($rootScope) { + it('should have $element set to current bind element', inject(function($rootScope, $compile) { var innerText; angularFilter.myFilter = function(text) { innerText = innerText || this.$element.text(); return text; }; - var element = angular.compile('
    beforeINNERafter
    ')($rootScope); + var element = $compile('
    beforeINNERafter
    ')($rootScope); $rootScope.$digest(); expect(element.text()).toEqual("beforeHELLOafter"); expect(innerText).toEqual('INNER'); })); - it('should render object as JSON ignore $$', inject(function($rootScope) { - var element = angular.compile('
    {{ {key:"value", $$key:"hide"}  }}
    ')($rootScope); + it('should render object as JSON ignore $$', inject(function($rootScope, $compile) { + var element = $compile('
    {{ {key:"value", $$key:"hide"}  }}
    ')($rootScope); $rootScope.$digest(); expect(fromJson(element.text())).toEqual({key:'value'}); })); @@ -104,22 +104,22 @@ describe("directive", function() { }); describe('ng:bind-attr', function() { - it('should bind attributes', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should bind attributes', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect(element.attr('src')).toEqual('http://localhost/mysrc'); expect(element.attr('alt')).toEqual('myalt'); })); - it('should not pretty print JSON in attributes', inject(function($rootScope) { - var element = angular.compile('{{ {a:1} }}')($rootScope); + it('should not pretty print JSON in attributes', inject(function($rootScope, $compile) { + var element = $compile('{{ {a:1} }}')($rootScope); $rootScope.$digest(); expect(element.attr('alt')).toEqual('{"a":1}'); })); }); - it('should remove special attributes on false', inject(function($rootScope) { - var element = angular.compile('')($rootScope); + it('should remove special attributes on false', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope); var input = element[0]; expect(input.disabled).toEqual(false); expect(input.readOnly).toEqual(false); @@ -136,8 +136,8 @@ describe("directive", function() { })); describe('ng:click', function() { - it('should get called on a click', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should get called on a click', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect($rootScope.clicked).toBeFalsy(); @@ -145,8 +145,8 @@ describe("directive", function() { expect($rootScope.clicked).toEqual(true); })); - it('should stop event propagation', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should stop event propagation', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect($rootScope.outer).not.toBeDefined(); expect($rootScope.inner).not.toBeDefined(); @@ -161,8 +161,8 @@ describe("directive", function() { describe('ng:submit', function() { - it('should get called on form submit', inject(function($rootScope) { - var element = angular.compile('
    ' + + it('should get called on form submit', inject(function($rootScope, $compile) { + var element = $compile('' + '' + '
    ')($rootScope); $rootScope.$digest(); @@ -174,8 +174,8 @@ describe("directive", function() { }); describe('ng:class', function() { - it('should add new and remove old classes dynamically', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should add new and remove old classes dynamically', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynClass = 'A'; $rootScope.$digest(); expect(element.hasClass('existing')).toBe(true); @@ -195,8 +195,8 @@ describe("directive", function() { })); - it('should support adding multiple classes via an array', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should support adding multiple classes via an array', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); @@ -204,8 +204,8 @@ describe("directive", function() { })); - it('should support adding multiple classes via a space delimited string', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should support adding multiple classes via a space delimited string', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.$digest(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); @@ -213,8 +213,8 @@ describe("directive", function() { })); - it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should preserve class added post compilation with pre-existing classes', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynClass = 'A'; $rootScope.$digest(); expect(element.hasClass('existing')).toBe(true); @@ -230,8 +230,8 @@ describe("directive", function() { })); - it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should preserve class added post compilation without pre-existing classes"', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynClass = 'A'; $rootScope.$digest(); expect(element.hasClass('A')).toBe(true); @@ -246,8 +246,8 @@ describe("directive", function() { })); - it('should preserve other classes with similar name"', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should preserve other classes with similar name"', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynCls = 'panel'; $rootScope.$digest(); $rootScope.dynCls = 'foo'; @@ -256,16 +256,16 @@ describe("directive", function() { })); - it('should not add duplicate classes', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should not add duplicate classes', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynCls = 'panel'; $rootScope.$digest(); expect(element[0].className).toBe('panel bar ng-directive'); })); - it('should remove classes even if it was specified via class attribute', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should remove classes even if it was specified via class attribute', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynCls = 'panel'; $rootScope.$digest(); $rootScope.dynCls = 'window'; @@ -274,8 +274,8 @@ describe("directive", function() { })); - it('should remove classes even if they were added by another code', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should remove classes even if they were added by another code', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynCls = 'foo'; $rootScope.$digest(); element.addClass('foo'); @@ -285,8 +285,8 @@ describe("directive", function() { })); - it('should convert undefined and null values to an empty string', inject(function($rootScope) { - var element = angular.compile('
    ')($rootScope); + it('should convert undefined and null values to an empty string', inject(function($rootScope, $compile) { + var element = $compile('
    ')($rootScope); $rootScope.dynCls = [undefined, null]; $rootScope.$digest(); expect(element[0].className).toBe('ng-directive'); @@ -294,8 +294,8 @@ describe("directive", function() { }); - it('should ng:class odd/even', inject(function($rootScope) { - var element = angular.compile('
      • ')($rootScope); + it('should ng:class odd/even', inject(function($rootScope, $compile) { + var element = $compile('
          • ')($rootScope); $rootScope.$digest(); var e1 = jqLite(element[0].childNodes[1]); var e2 = jqLite(element[0].childNodes[2]); @@ -306,8 +306,8 @@ describe("directive", function() { })); - it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope) { - var element = angular.compile('
              ' + + it('should allow both ng:class and ng:class-odd/even on the same element', inject(function($rootScope, $compile) { + var element = $compile('
                ' + '
              • ' + '
                  ')($rootScope); @@ -324,8 +324,8 @@ describe("directive", function() { })); - it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope) { - var element = angular.compile('
                    ' + + it('should allow both ng:class and ng:class-odd/even with multiple classes', inject(function($rootScope, $compile) { + var element = $compile('
                      ' + '
                    • ' + '
                        ')($rootScope); @@ -351,15 +351,15 @@ describe("directive", function() { describe('ng:style', function() { - it('should set', inject(function($rootScope) { - var element = angular.compile('
                        ')($rootScope); + it('should set', inject(function($rootScope, $compile) { + var element = $compile('
                        ')($rootScope); $rootScope.$digest(); expect(element.css('height')).toEqual('40px'); })); - it('should silently ignore undefined style', inject(function($rootScope) { - var element = angular.compile('
                        ')($rootScope); + it('should silently ignore undefined style', inject(function($rootScope, $compile) { + var element = $compile('
                        ')($rootScope); $rootScope.$digest(); expect(element.hasClass('ng-exception')).toBeFalsy(); })); @@ -368,7 +368,7 @@ describe("directive", function() { describe('preserving styles set before and after compilation', function() { var scope, preCompStyle, preCompVal, postCompStyle, postCompVal, element; - beforeEach(inject(function($rootScope) { + beforeEach(inject(function($rootScope, $compile) { preCompStyle = 'width'; preCompVal = '300px'; postCompStyle = 'height'; @@ -376,7 +376,7 @@ describe("directive", function() { element = jqLite('
                        '); element.css(preCompStyle, preCompVal); jqLite(document.body).append(element); - angular.compile(element)($rootScope); + $compile(element)($rootScope); scope = $rootScope; scope.styleObj = {'margin-top': '44px'}; scope.$apply(); @@ -431,9 +431,9 @@ describe("directive", function() { describe('ng:show', function() { - it('should show and hide an element', inject(function($rootScope) { + it('should show and hide an element', inject(function($rootScope, $compile) { var element = jqLite('
                        '); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); $rootScope.$digest(); expect(isCssVisible(element)).toEqual(false); $rootScope.exp = true; @@ -442,9 +442,9 @@ describe("directive", function() { })); - it('should make hidden element visible', inject(function($rootScope) { + it('should make hidden element visible', inject(function($rootScope, $compile) { var element = jqLite('
                        '); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); expect(isCssVisible(element)).toBe(false); $rootScope.exp = true; $rootScope.$digest(); @@ -453,9 +453,9 @@ describe("directive", function() { }); describe('ng:hide', function() { - it('should hide an element', inject(function($rootScope) { + it('should hide an element', inject(function($rootScope, $compile) { var element = jqLite('
                        '); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); expect(isCssVisible(element)).toBe(true); $rootScope.exp = true; $rootScope.$digest(); @@ -485,13 +485,13 @@ describe("directive", function() { window.temp = undefined; }); - it('should bind', inject(function($rootScope) { - var element = angular.compile('
                        ')($rootScope); + it('should bind', inject(function($rootScope, $compile) { + var element = $compile('
                        ')($rootScope); expect($rootScope.greeter.greeting).toEqual('hello'); expect($rootScope.greeter.greet('misko')).toEqual('hello misko!'); })); - it('should support nested controllers', inject(function($rootScope) { + it('should support nested controllers', inject(function($rootScope, $compile) { temp.ChildGreeter = function() { this.greeting = 'hey'; this.$root.childGreeter = this; @@ -501,7 +501,7 @@ describe("directive", function() { return this.greeting + ' dude' + this.suffix; } }; - var element = angular.compile('
                        {{greet("misko")}}
                        ')($rootScope); + var element = $compile('
                        {{greet("misko")}}
                        ')($rootScope); expect($rootScope.greeting).not.toBeDefined(); expect($rootScope.greeter.greeting).toEqual('hello'); expect($rootScope.greeter.greet('misko')).toEqual('hello misko!'); @@ -512,33 +512,33 @@ describe("directive", function() { expect(element.text()).toEqual('hey dude!'); })); - it('should infer injection arguments', inject(function($rootScope) { + it('should infer injection arguments', inject(function($rootScope, $compile) { temp.MyController = function($xhr){ this.$root.someService = $xhr; }; - var element = angular.compile('
                        ')($rootScope); + var element = $compile('
                        ')($rootScope); expect($rootScope.someService).toBe($rootScope.$service('$xhr')); })); }); describe('ng:cloak', function() { - it('should get removed when an element is compiled', inject(function($rootScope) { + it('should get removed when an element is compiled', inject(function($rootScope, $compile) { var element = jqLite('
                        '); expect(element.attr('ng:cloak')).toBe(''); - angular.compile(element); + $compile(element); expect(element.attr('ng:cloak')).toBeUndefined(); })); - it('should remove ng-cloak class from a compiled element', inject(function($rootScope) { + it('should remove ng-cloak class from a compiled element', inject(function($rootScope, $compile) { var element = jqLite('
                        '); expect(element.hasClass('foo')).toBe(true); expect(element.hasClass('ng-cloak')).toBe(true); expect(element.hasClass('bar')).toBe(true); - angular.compile(element); + $compile(element); expect(element.hasClass('foo')).toBe(true); expect(element.hasClass('ng-cloak')).toBe(false); diff --git a/test/markupSpec.js b/test/markupSpec.js index d97dbcb5..c23cc62d 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -2,16 +2,16 @@ describe("markups", function() { - it('should translate {{}} in text', inject(function($rootScope) { - var element = angular.compile('
                        hello {{name}}!
                        ')($rootScope) + it('should translate {{}} in text', inject(function($rootScope, $compile) { + var element = $compile('
                        hello {{name}}!
                        ')($rootScope) expect(sortedHtml(element)).toEqual('
                        hello !
                        '); $rootScope.name = 'Misko'; $rootScope.$digest(); expect(sortedHtml(element)).toEqual('
                        hello Misko!
                        '); })); - it('should translate {{}} in terminal nodes', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should translate {{}} in terminal nodes', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) $rootScope.$digest(); expect(sortedHtml(element).replace(' selected="true"', '')). toEqual(''); })); - it('should translate {{}} in attributes', inject(function($rootScope) { - var element = angular.compile('
                        ')($rootScope) + it('should translate {{}} in attributes', inject(function($rootScope, $compile) { + var element = $compile('
                        ')($rootScope) expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); $rootScope.path = 'a/b'; $rootScope.$digest(); @@ -55,37 +55,37 @@ describe("markups", function() { }); - it('should populate value attribute on OPTION', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should populate value attribute on OPTION', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) expect(element).toHaveValue('abc'); })); - it('should ignore value if already exists', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should ignore value if already exists', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) expect(element).toHaveValue('abc'); })); - it('should set value even if newlines present', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should set value even if newlines present', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) expect(element).toHaveValue('\nabc\n'); })); - it('should set value even if self closing HTML', inject(function($rootScope) { + it('should set value even if self closing HTML', inject(function($rootScope, $compile) { // IE removes the \n from option, which makes this test pointless if (msie) return; - var element = angular.compile('')($rootScope) + var element = $compile('')($rootScope) expect(element).toHaveValue('\n'); })); }); - it('should bind href', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind href', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) expect(sortedHtml(element)).toEqual(''); })); - it('should bind disabled', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind disabled', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) $rootScope.isDisabled = false; $rootScope.$digest(); expect(element.attr('disabled')).toBeFalsy(); @@ -94,8 +94,8 @@ describe("markups", function() { expect(element.attr('disabled')).toBeTruthy(); })); - it('should bind checked', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind checked', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) $rootScope.isChecked = false; $rootScope.$digest(); expect(element.attr('checked')).toBeFalsy(); @@ -104,8 +104,8 @@ describe("markups", function() { expect(element.attr('checked')).toBeTruthy(); })); - it('should bind selected', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind selected', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) jqLite(document.body).append(element) $rootScope.isSelected=false; $rootScope.$digest(); @@ -115,8 +115,8 @@ describe("markups", function() { expect(element.children()[1].selected).toBeTruthy(); })); - it('should bind readonly', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind readonly', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) $rootScope.isReadonly=false; $rootScope.$digest(); expect(element.attr('readOnly')).toBeFalsy(); @@ -125,8 +125,8 @@ describe("markups", function() { expect(element.attr('readOnly')).toBeTruthy(); })); - it('should bind multiple', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind multiple', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) $rootScope.isMultiple=false; $rootScope.$digest(); expect(element.attr('multiple')).toBeFalsy(); @@ -135,57 +135,57 @@ describe("markups", function() { expect(element.attr('multiple')).toBeTruthy(); })); - it('should bind src', inject(function($rootScope) { - var element = angular.compile('
                        ')($rootScope) + it('should bind src', inject(function($rootScope, $compile) { + var element = $compile('
                        ')($rootScope) $rootScope.url = 'http://localhost/'; $rootScope.$digest(); expect(element.attr('src')).toEqual('http://localhost/'); })); - it('should bind href and merge with other attrs', inject(function($rootScope) { - var element = angular.compile('')($rootScope) + it('should bind href and merge with other attrs', inject(function($rootScope, $compile) { + var element = $compile('')($rootScope) expect(sortedHtml(element)).toEqual(''); })); - it('should bind Text with no Bindings', inject(function() { + it('should bind Text with no Bindings', inject(function($compile) { var $rootScope; function newScope (){ return $rootScope = angular.injector()('$rootScope'); } forEach(['checked', 'disabled', 'multiple', 'readonly', 'selected'], function(name) { - var element = angular.compile('
                        ')(newScope()) + var element = $compile('
                        ')(newScope()) expect(element.attr('ng:bind-attr')).toBe('{"' + name +'":"some"}'); $rootScope.$digest(); expect(element.attr(name)).toBe(name); dealoc(element); }); - var element = angular.compile('
                        ')(newScope()) + var element = $compile('
                        ')(newScope()) $rootScope.$digest(); expect(sortedHtml(element)).toEqual('
                        '); dealoc(element); - var element = angular.compile('
                        ')(newScope()) + var element = $compile('
                        ')(newScope()) $rootScope.$digest(); expect(sortedHtml(element)).toEqual('
                        '); dealoc(element); })); - it('should Parse Text With No Bindings', inject(function($rootScope) { + it('should Parse Text With No Bindings', inject(function($rootScope, $compile) { var parts = parseBindings("a"); assertEquals(parts.length, 1); assertEquals(parts[0], "a"); assertTrue(!binding(parts[0])); })); - it('should Parse Empty Text', inject(function($rootScope) { + it('should Parse Empty Text', inject(function($rootScope, $compile) { var parts = parseBindings(""); assertEquals(parts.length, 1); assertEquals(parts[0], ""); assertTrue(!binding(parts[0])); })); - it('should Parse Inner Binding', inject(function($rootScope) { + it('should Parse Inner Binding', inject(function($rootScope, $compile) { var parts = parseBindings("a{{b}}C"); assertEquals(parts.length, 3); assertEquals(parts[0], "a"); @@ -196,7 +196,7 @@ describe("markups", function() { assertTrue(!binding(parts[2])); })); - it('should Parse Ending Binding', inject(function($rootScope) { + it('should Parse Ending Binding', inject(function($rootScope, $compile) { var parts = parseBindings("a{{b}}"); assertEquals(parts.length, 2); assertEquals(parts[0], "a"); @@ -205,7 +205,7 @@ describe("markups", function() { assertEquals(binding(parts[1]), "b"); })); - it('should Parse Begging Binding', inject(function($rootScope) { + it('should Parse Begging Binding', inject(function($rootScope, $compile) { var parts = parseBindings("{{b}}c"); assertEquals(parts.length, 2); assertEquals(parts[0], "{{b}}"); @@ -214,14 +214,14 @@ describe("markups", function() { assertTrue(!binding(parts[1])); })); - it('should Parse Loan Binding', inject(function($rootScope) { + it('should Parse Loan Binding', inject(function($rootScope, $compile) { var parts = parseBindings("{{b}}"); assertEquals(parts.length, 1); assertEquals(parts[0], "{{b}}"); assertEquals(binding(parts[0]), "b"); })); - it('should Parse Two Bindings', inject(function($rootScope) { + it('should Parse Two Bindings', inject(function($rootScope, $compile) { var parts = parseBindings("{{b}}{{c}}"); assertEquals(parts.length, 2); assertEquals(parts[0], "{{b}}"); @@ -230,7 +230,7 @@ describe("markups", function() { assertEquals(binding(parts[1]), "c"); })); - it('should Parse Two Bindings With Text In Middle', inject(function($rootScope) { + it('should Parse Two Bindings With Text In Middle', inject(function($rootScope, $compile) { var parts = parseBindings("{{b}}x{{c}}"); assertEquals(parts.length, 3); assertEquals(parts[0], "{{b}}"); @@ -241,7 +241,7 @@ describe("markups", function() { assertEquals(binding(parts[2]), "c"); })); - it('should Parse Multiline', inject(function($rootScope) { + it('should Parse Multiline', inject(function($rootScope, $compile) { var parts = parseBindings('"X\nY{{A\nB}}C\nD"'); assertTrue(!!binding('{{A\nB}}')); assertEquals(parts.length, 3); @@ -250,7 +250,7 @@ describe("markups", function() { assertEquals(parts[2], 'C\nD"'); })); - it('should Has Binding', inject(function($rootScope) { + it('should Has Binding', inject(function($rootScope, $compile) { assertTrue(hasBindings(parseBindings("{{a}}"))); assertTrue(!hasBindings(parseBindings("a"))); assertTrue(hasBindings(parseBindings("{{b}}x{{c}}"))); diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js index 2dec1396..4e0dbed6 100644 --- a/test/service/compilerSpec.js +++ b/test/service/compilerSpec.js @@ -1,10 +1,12 @@ 'use strict'; describe('compiler', function() { - var compiler, markup, attrMarkup, directives, widgets, compile, log, scope; + var compiler, textMmarkup, attrMarkup, directives, widgets, compile, log, $rootScope; - beforeEach(inject(function($rootScope) { - log = ""; + beforeEach(inject(function(service){ + textMmarkup = []; + attrMarkup = []; + widgets = extensionMap({}, 'widget'); directives = { hello: function(expression, element){ log += "hello "; @@ -23,29 +25,25 @@ describe('compiler', function() { } }; - markup = []; - attrMarkup = []; - widgets = extensionMap({}, 'widget'); - compiler = new Compiler(markup, attrMarkup, directives, widgets); - compile = function(html){ - var e = jqLite("
                        " + html + "
                        "); - compiler.compile(e)($rootScope); - return scope = $rootScope; - }; + log = ""; + service('$textMarkup', valueFn(textMmarkup)); + service('$attrMarkup', valueFn(attrMarkup)); + service('$directive', valueFn(directives)); + service('$widget', valueFn(widgets)); })); - it('should not allow compilation of multiple roots', function() { + it('should not allow compilation of multiple roots', inject(function($rootScope, $compile) { expect(function() { - compiler.compile('
                        A
                        '); + $compile('
                        A
                        '); }).toThrow("Cannot compile multiple element roots: " + ie("
                        A
                        ")); function ie(text) { return msie < 9 ? uppercase(text) : text; } - }); + })); - it('should recognize a directive', inject(function($rootScope) { + it('should recognize a directive', inject(function($rootScope, $compile) { var e = jqLite('
                        '); directives.directive = function(expression, element){ log += "found"; @@ -55,42 +53,42 @@ describe('compiler', function() { log += ":init"; }; }; - var template = compiler.compile(e); + var linkFn = $compile(e); expect(log).toEqual("found"); - scope = template($rootScope); + linkFn($rootScope); expect(e.hasClass('ng-directive')).toEqual(true); expect(log).toEqual("found:init"); })); - it('should recurse to children', function() { - scope = compile('
                        '); + it('should recurse to children', inject(function($rootScope, $compile) { + $compile('
                        ')($rootScope); expect(log).toEqual("hello misko"); - }); + })); - it('should observe scope', function() { - scope = compile(''); + it('should observe scope', inject(function($rootScope, $compile) { + $compile('')($rootScope); expect(log).toEqual(""); - scope.$digest(); - scope.name = 'misko'; - scope.$digest(); - scope.$digest(); - scope.name = 'adam'; - scope.$digest(); - scope.$digest(); + $rootScope.$digest(); + $rootScope.name = 'misko'; + $rootScope.$digest(); + $rootScope.$digest(); + $rootScope.name = 'adam'; + $rootScope.$digest(); + $rootScope.$digest(); expect(log).toEqual(":misko:adam"); - }); + })); - it('should prevent descend', function() { + it('should prevent descend', inject(function($rootScope, $compile) { directives.stop = function() { this.descend(false); }; - scope = compile(''); + $compile('')($rootScope); expect(log).toEqual("hello misko"); - }); + })); - it('should allow creation of templates', inject(function($rootScope) { + it('should allow creation of templates', inject(function($rootScope, $compile) { directives.duplicate = function(expr, element){ element.replaceWith(document.createComment("marker")); element.removeAttr("duplicate"); @@ -103,32 +101,32 @@ describe('compiler', function() { }); }; }; - scope = compile('beforexafter'); - expect(sortedHtml(scope.$element)). + $compile('
                        beforexafter
                        ')($rootScope); + expect(sortedHtml($rootScope.$element)). toEqual('
                        ' + 'before<#comment>' + 'after' + '
                        '); - scope.value = 1; - scope.$digest(); - expect(sortedHtml(scope.$element)). + $rootScope.value = 1; + $rootScope.$digest(); + expect(sortedHtml($rootScope.$element)). toEqual('
                        ' + 'before<#comment>' + 'x' + 'after' + '
                        '); - scope.value = 2; - scope.$digest(); - expect(sortedHtml(scope.$element)). + $rootScope.value = 2; + $rootScope.$digest(); + expect(sortedHtml($rootScope.$element)). toEqual('
                        ' + 'before<#comment>' + 'x' + 'x' + 'after' + '
                        '); - scope.value = 3; - scope.$digest(); - expect(sortedHtml(scope.$element)). + $rootScope.value = 3; + $rootScope.$digest(); + expect(sortedHtml($rootScope.$element)). toEqual('
                        ' + 'before<#comment>' + 'x' + @@ -139,21 +137,22 @@ describe('compiler', function() { })); - it('should process markup before directives', function() { - markup.push(function(text, textNode, parentNode) { + it('should process markup before directives', inject(function($rootScope, $compile) { + textMmarkup.push(function(text, textNode, parentNode) { if (text == 'middle') { expect(textNode.text()).toEqual(text); parentNode.attr('hello', text); textNode[0].nodeValue = 'replaced'; } }); - scope = compile('beforemiddleafter'); - expect(sortedHtml(scope.$element[0], true)).toEqual('
                        beforereplacedafter
                        '); + $compile('
                        beforemiddleafter
                        ')($rootScope); + expect(sortedHtml($rootScope.$element[0], true)). + toEqual('
                        beforereplacedafter
                        '); expect(log).toEqual("hello middle"); - }); + })); - it('should replace widgets', function() { + it('should replace widgets', inject(function($rootScope, $compile) { widgets['NG:BUTTON'] = function(element) { expect(element.hasClass('ng-widget')).toEqual(true); element.replaceWith('
                        button
                        '); @@ -161,13 +160,13 @@ describe('compiler', function() { log += 'init'; }; }; - scope = compile('push me'); - expect(lowercase(scope.$element[0].innerHTML)).toEqual('
                        button
                        '); + $compile('
                        push me
                        ')($rootScope); + expect(lowercase($rootScope.$element[0].innerHTML)).toEqual('
                        button
                        '); expect(log).toEqual('init'); - }); + })); - it('should use the replaced element after calling widget', function() { + it('should use the replaced element after calling widget', inject(function($rootScope, $compile) { widgets['H1'] = function(element) { // HTML elements which are augmented by acting as widgets, should not be marked as so expect(element.hasClass('ng-widget')).toEqual(false); @@ -177,17 +176,17 @@ describe('compiler', function() { this.directives(true); return noop; }; - markup.push(function(text, textNode, parent){ + textMmarkup.push(function(text, textNode, parent){ if (text == '{{1+2}}') parent.text('3'); }); - scope = compile('

                        ignore me

                        '); - expect(scope.$element.text()).toEqual('3'); - }); + $compile('

                        ignore me

                        ')($rootScope); + expect($rootScope.$element.text()).toEqual('3'); + })); - it('should allow multiple markups per text element', function() { - markup.push(function(text, textNode, parent){ + it('should allow multiple markups per text element', inject(function($rootScope, $compile) { + textMmarkup.push(function(text, textNode, parent){ var index = text.indexOf('---'); if (index > -1) { textNode.after(text.substring(index + 3)); @@ -196,7 +195,7 @@ describe('compiler', function() { textNode.remove(); } }); - markup.push(function(text, textNode, parent){ + textMmarkup.push(function(text, textNode, parent){ var index = text.indexOf('==='); if (index > -1) { textNode.after(text.substring(index + 3)); @@ -205,14 +204,13 @@ describe('compiler', function() { textNode.remove(); } }); - scope = compile('A---B---C===D'); - expect(sortedHtml(scope.$element)).toEqual('
                        A
                        B
                        C

                        D
                        '); - }); + $compile('
                        A---B---C===D
                        ')($rootScope); + expect(sortedHtml($rootScope.$element)).toEqual('
                        A
                        B
                        C

                        D
                        '); + })); - it('should add class for namespace elements', function() { - scope = compile('abc'); - var space = jqLite(scope.$element[0].firstChild); - expect(space.hasClass('ng-space')).toEqual(true); - }); + it('should add class for namespace elements', inject(function($rootScope, $compile) { + var element = $compile('abc')($rootScope); + expect(element.hasClass('ng-space')).toEqual(true); + })); }); diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index 3d964149..154db7d0 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -125,7 +125,6 @@ function inject(){ function resetAngularPublic() { extend(angular, { 'element': jqLite, - 'compile': compile, 'copy': copy, 'extend': extend, 'equals': equals, 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; }; diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 1a4c5e6c..d2204540 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -1,9 +1,10 @@ 'use strict'; describe("widget", function() { - describe('ng:switch', inject(function($rootScope) { - it('should switch on value change', inject(function($rootScope) { - var element = angular.compile('' + + describe('ng:switch', inject(function($rootScope, $compile) { + it('should switch on value change', inject(function($rootScope, $compile) { + var element = $compile( + '' + '
                        first:{{name}}
                        ' + '
                        second:{{name}}
                        ' + '
                        true:{{name}}
                        ' + @@ -27,8 +28,8 @@ describe("widget", function() { })); - it('should switch on switch-when-default', inject(function($rootScope) { - var element = angular.compile( + it('should switch on switch-when-default', inject(function($rootScope, $compile) { + var element = $compile( '' + '
                        one
                        ' + '
                        other
                        ' + @@ -41,8 +42,8 @@ describe("widget", function() { })); - it('should call change on switch', inject(function($rootScope) { - var element = angular.compile( + it('should call change on switch', inject(function($rootScope, $compile) { + var element = $compile( '' + '
                        {{name}}
                        ' + '
                        ')($rootScope); @@ -54,10 +55,10 @@ describe("widget", function() { })); - describe('ng:include', inject(function($rootScope) { - it('should include on external file', inject(function($rootScope) { + describe('ng:include', inject(function($rootScope, $compile) { + it('should include on external file', inject(function($rootScope, $compile) { var element = jqLite(''); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); $rootScope.childScope = $rootScope.$new(); $rootScope.childScope.name = 'misko'; $rootScope.url = 'myUrl'; @@ -67,9 +68,9 @@ describe("widget", function() { })); - it('should remove previously included text if a falsy value is bound to src', inject(function($rootScope) { + it('should remove previously included text if a falsy value is bound to src', inject(function($rootScope, $compile) { var element = jqLite(''); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); $rootScope.childScope = $rootScope.$new(); $rootScope.childScope.name = 'igor'; $rootScope.url = 'myUrl'; @@ -85,9 +86,9 @@ describe("widget", function() { })); - it('should allow this for scope', inject(function($rootScope) { + it('should allow this for scope', inject(function($rootScope, $compile) { var element = jqLite(''); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); $rootScope.url = 'myUrl'; $rootScope.$service('$xhr.cache').data.myUrl = {value:'{{"abc"}}'}; $rootScope.$digest(); @@ -101,9 +102,9 @@ describe("widget", function() { })); - it('should evaluate onload expression when a partial is loaded', inject(function($rootScope) { + it('should evaluate onload expression when a partial is loaded', inject(function($rootScope, $compile) { var element = jqLite(''); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); expect($rootScope.loaded).not.toBeDefined(); @@ -115,9 +116,9 @@ describe("widget", function() { })); - it('should destroy old scope', inject(function($rootScope) { + it('should destroy old scope', inject(function($rootScope, $compile) { var element = jqLite(''); - var element = angular.compile(element)($rootScope); + var element = $compile(element)($rootScope); expect($rootScope.$$childHead).toBeFalsy(); @@ -133,13 +134,13 @@ describe("widget", function() { })); - describe('a', inject(function($rootScope) { - it('should prevent default action to be executed when href is empty', inject(function($rootScope) { + describe('a', inject(function($rootScope, $compile) { + it('should prevent default action to be executed when href is empty', inject(function($rootScope, $compile) { var orgLocation = document.location.href, preventDefaultCalled = false, event; - var element = angular.compile('empty link')($rootScope); + var element = $compile('empty link')($rootScope); if (msie < 9) { @@ -169,9 +170,9 @@ describe("widget", function() { })); - describe('@ng:repeat', inject(function($rootScope) { - it('should ng:repeat over array', inject(function($rootScope) { - var element = angular.compile( + describe('@ng:repeat', inject(function($rootScope, $compile) { + it('should ng:repeat over array', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -197,8 +198,8 @@ describe("widget", function() { expect(element.text()).toEqual('brad;'); })); - it('should ng:repeat over object', inject(function($rootScope) { - var element = angular.compile( + it('should ng:repeat over object', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -207,12 +208,12 @@ describe("widget", function() { expect(element.text()).toEqual('misko:swe;shyam:set;'); })); - it('should not ng:repeat over parent properties', inject(function($rootScope) { + it('should not ng:repeat over parent properties', inject(function($rootScope, $compile) { var Class = function() {}; Class.prototype.abc = function() {}; Class.prototype.value = 'abc'; - var element = angular.compile( + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -222,16 +223,16 @@ describe("widget", function() { expect(element.text()).toEqual('name:value;'); })); - it('should error on wrong parsing of ng:repeat', inject(function($rootScope) { + it('should error on wrong parsing of ng:repeat', inject(function($rootScope, $compile) { expect(function() { - var element = angular.compile('
                        ')($rootScope); + var element = $compile('
                        ')($rootScope); }).toThrow("Expected ng:repeat in form of '_item_ in _collection_' but got 'i dont parse'."); $logMock.error.logs.shift(); })); - it('should expose iterator offset as $index when iterating over arrays', inject(function($rootScope) { - var element = angular.compile( + it('should expose iterator offset as $index when iterating over arrays', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -240,8 +241,8 @@ describe("widget", function() { expect(element.text()).toEqual('misko0|shyam1|frodo2|'); })); - it('should expose iterator offset as $index when iterating over objects', inject(function($rootScope) { - var element = angular.compile( + it('should expose iterator offset as $index when iterating over objects', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -250,9 +251,8 @@ describe("widget", function() { expect(element.text()).toEqual('frodo:f0|misko:m1|shyam:s2|'); })); - it('should expose iterator position as $position when iterating over arrays', - inject(function($rootScope) { - var element = angular.compile( + it('should expose iterator position as $position when iterating over arrays', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        ')($rootScope); @@ -270,8 +270,8 @@ describe("widget", function() { expect(element.text()).toEqual('misko:first|shyam:last|'); })); - it('should expose iterator position as $position when iterating over objects', inject(function($rootScope) { - var element = angular.compile( + it('should expose iterator position as $position when iterating over objects', inject(function($rootScope, $compile) { + var element = $compile( '
                          ' + '
                        • ' + '
                        • ' + @@ -286,8 +286,8 @@ describe("widget", function() { expect(element.text()).toEqual('misko:m:first|shyam:s:last|'); })); - it('should ignore $ and $$ properties', inject(function($rootScope) { - var element = angular.compile('
                          • {{i}}|
                          ')($rootScope); + it('should ignore $ and $$ properties', inject(function($rootScope, $compile) { + var element = $compile('
                          • {{i}}|
                          ')($rootScope); $rootScope.items = ['a', 'b', 'c']; $rootScope.items.$$hashkey = 'xxx'; $rootScope.items.$root = 'yyy'; @@ -296,8 +296,8 @@ describe("widget", function() { expect(element.text()).toEqual('a|b|c|'); })); - it('should repeat over nested arrays', inject(function($rootScope) { - var element = angular.compile( + it('should repeat over nested arrays', inject(function($rootScope, $compile) { + var element = $compile( '
                            ' + '
                          • ' + '
                            {{group}}|
                            X' + @@ -309,8 +309,8 @@ describe("widget", function() { expect(element.text()).toEqual('a|b|Xc|d|X'); })); - it('should ignore non-array element properties when iterating over an array', inject(function($rootScope) { - var element = angular.compile('
                            • {{item}}|
                            ')($rootScope); + it('should ignore non-array element properties when iterating over an array', inject(function($rootScope, $compile) { + var element = $compile('
                            • {{item}}|
                            ')($rootScope); $rootScope.array = ['a', 'b', 'c']; $rootScope.array.foo = '23'; $rootScope.array.bar = function() {}; @@ -319,8 +319,8 @@ describe("widget", function() { expect(element.text()).toBe('a|b|c|'); })); - it('should iterate over non-existent elements of a sparse array', inject(function($rootScope) { - var element = angular.compile('
                            • {{item}}|
                            ')($rootScope); + it('should iterate over non-existent elements of a sparse array', inject(function($rootScope, $compile) { + var element = $compile('
                            • {{item}}|
                            ')($rootScope); $rootScope.array = ['a', 'b']; $rootScope.array[4] = 'c'; $rootScope.array[6] = 'd'; @@ -333,8 +333,8 @@ describe("widget", function() { describe('stability', function() { var a, b, c, d, lis, element; - beforeEach(inject(function($rootScope) { - element = angular.compile( + beforeEach(inject(function($rootScope, $compile) { + element = $compile( '
                              ' + '
                            • ' + '
                            ')($rootScope); @@ -348,7 +348,7 @@ describe("widget", function() { lis = element.find('li'); })); - it('should preserve the order of elements', inject(function($rootScope) { + it('should preserve the order of elements', inject(function($rootScope, $compile) { $rootScope.items = [a, c, d]; $rootScope.$digest(); var newElements = element.find('li'); @@ -357,7 +357,7 @@ describe("widget", function() { expect(newElements[2]).not.toEqual(lis[1]); })); - it('should support duplicates', inject(function($rootScope) { + it('should support duplicates', inject(function($rootScope, $compile) { $rootScope.items = [a, a, b, c]; $rootScope.$digest(); var newElements = element.find('li'); @@ -382,7 +382,7 @@ describe("widget", function() { expect(newElements[3]).toEqual(lis[3]); })); - it('should remove last item when one duplicate instance is removed', inject(function($rootScope) { + it('should remove last item when one duplicate instance is removed', inject(function($rootScope, $compile) { $rootScope.items = [a, a, a]; $rootScope.$digest(); lis = element.find('li'); @@ -395,7 +395,7 @@ describe("widget", function() { expect(newElements[1]).toEqual(lis[1]); })); - it('should reverse items when the collection is reversed', inject(function($rootScope) { + it('should reverse items when the collection is reversed', inject(function($rootScope, $compile) { $rootScope.items = [a, b, c]; $rootScope.$digest(); lis = element.find('li'); @@ -413,8 +413,8 @@ describe("widget", function() { describe('@ng:non-bindable', function() { - it('should prevent compilation of the owning element and its children', inject(function($rootScope) { - var element = angular.compile('
                            ')($rootScope); + it('should prevent compilation of the owning element and its children', inject(function($rootScope, $compile) { + var element = $compile('
                            ')($rootScope); $rootScope.name = 'misko'; $rootScope.$digest(); expect(element.text()).toEqual(''); @@ -424,19 +424,19 @@ describe("widget", function() { describe('ng:view', function() { var element; - beforeEach(inject(function($rootScope) { - element = angular.compile('')($rootScope); + beforeEach(inject(function($rootScope, $compile) { + element = $compile('')($rootScope); })); - it('should do nothing when no routes are defined', inject(function($rootScope, $location) { + it('should do nothing when no routes are defined', inject(function($rootScope, $compile, $location) { $location.path('/unknown'); $rootScope.$digest(); expect(element.text()).toEqual(''); })); - it('should load content via xhr when route changes', inject(function($rootScope, $browser, $location, $route) { + it('should load content via xhr when route changes', inject(function($rootScope, $compile, $browser, $location, $route) { $route.when('/foo', {template: 'myUrl1'}); $route.when('/bar', {template: 'myUrl2'}); @@ -456,7 +456,7 @@ describe("widget", function() { })); it('should remove all content when location changes to an unknown route', - inject(function($rootScope, $location, $browser, $route) { + inject(function($rootScope, $compile, $location, $browser, $route) { $route.when('/foo', {template: 'myUrl1'}); $location.path('/foo'); @@ -471,7 +471,7 @@ describe("widget", function() { })); it('should chain scopes and propagate evals to the child scope', - inject(function($rootScope, $location, $browser, $route) { + inject(function($rootScope, $compile, $location, $browser, $route) { $route.when('/foo', {template: 'myUrl1'}); $rootScope.parentVar = 'parent'; @@ -496,7 +496,7 @@ describe("widget", function() { var $route = injector('$route'); $route.when('/foo', {controller: angular.noop, template: 'viewPartial.html'}); - var element = angular.compile( + var element = injector('$compile')( '
                            ' + 'include: ' + '
                            ')(myApp); @@ -512,8 +512,8 @@ describe("widget", function() { })); it('should initialize view template after the view controller was initialized even when ' + - 'templates were cached', inject(function($rootScope, $location, $browser, $route) { - // this is a test for a regression that was introduced by making the ng:view cache sync + 'templates were cached', inject(function($rootScope, $compile, $location, $browser, $route) { + //this is a test for a regression that was introduced by making the ng:view cache sync $route.when('/foo', {controller: ParentCtrl, template: 'viewPartial.html'}); @@ -576,8 +576,8 @@ describe("widget", function() { describe('deal with pluralized strings without offset', function() { var element; - beforeEach(inject(function($rootScope) { - element = angular.compile( + beforeEach(inject(function($rootScope, $compile) { + element = $compile( '')($rootScope); })); - it('should show single/plural strings', inject(function($rootScope) { + it('should show single/plural strings', inject(function($rootScope, $compile) { $rootScope.email = 0; $rootScope.$digest(); expect(element.text()).toBe('You have no new email'); @@ -624,7 +624,7 @@ describe("widget", function() { })); - it('should show single/plural strings with mal-formed inputs', inject(function($rootScope) { + it('should show single/plural strings with mal-formed inputs', inject(function($rootScope, $compile) { $rootScope.email = ''; $rootScope.$digest(); expect(element.text()).toBe(''); @@ -665,8 +665,8 @@ describe("widget", function() { describe('deal with pluralized strings with offset', function() { - it('should show single/plural strings with offset', inject(function($rootScope) { - var element = angular.compile( + it('should show single/plural strings with offset', inject(function($rootScope, $compile) { + var element = $compile( "