diff options
Diffstat (limited to 'test/BinderSpec.js')
| -rw-r--r-- | test/BinderSpec.js | 146 |
1 files changed, 73 insertions, 73 deletions
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('<div ng:init="a=123"/>')($rootScope); + it('BindUpdate', inject(function($rootScope, $compile) { + $compile('<div ng:init="a=123"/>')($rootScope); $rootScope.$digest(); assertEquals(123, $rootScope.a); })); - it('ExecuteInitialization', inject(function($rootScope) { - angular.compile('<div ng:init="a=123">')($rootScope); + it('ExecuteInitialization', inject(function($rootScope, $compile) { + $compile('<div ng:init="a=123">')($rootScope); assertEquals($rootScope.a, 123); })); - it('ExecuteInitializationStatements', inject(function($rootScope) { - angular.compile('<div ng:init="a=123;b=345">')($rootScope); + it('ExecuteInitializationStatements', inject(function($rootScope, $compile) { + $compile('<div ng:init="a=123;b=345">')($rootScope); assertEquals($rootScope.a, 123); assertEquals($rootScope.b, 345); })); - it('ApplyTextBindings', inject(function($rootScope) { - var element = angular.compile('<div ng:bind="model.a">x</div>')($rootScope); + it('ApplyTextBindings', inject(function($rootScope, $compile) { + var element = $compile('<div ng:bind="model.a">x</div>')($rootScope); $rootScope.model = {a:123}; $rootScope.$apply(); assertEquals('123', element.text()); @@ -51,7 +51,7 @@ describe('Binder', function() { assertEquals(this.compileToHtml("<b>{{b}}</b>"), '<b><span ng:bind="b"></span></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("<b>{{A}} x {{B}} ({{C}})</b>")); })); - it('BindingOfAttributes', inject(function($rootScope) { - var element = angular.compile("<a href='http://s/a{{b}}c' foo='x'></a>")($rootScope); + it('BindingOfAttributes', inject(function($rootScope, $compile) { + var element = $compile("<a href='http://s/a{{b}}c' foo='x'></a>")($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('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($rootScope); + it('MarkMultipleAttributes', inject(function($rootScope, $compile) { + var element = $compile('<a href="http://s/a{{b}}c" foo="{{d}}"></a>')($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("<a href='abc' foo='def'></a>")($rootScope); + it('AttributesNoneBound', inject(function($rootScope, $compile) { + var a = $compile("<a href='abc' foo='def'></a>")($rootScope); assertEquals(a[0].nodeName, "A"); assertTrue(!a.attr("ng:bind-attr")); })); - it('ExistingAttrbindingIsAppended', inject(function($rootScope) { - var a = angular.compile("<a href='http://s/{{abc}}' ng:bind-attr='{\"b\":\"{{def}}\"}'></a>")($rootScope); + it('ExistingAttrbindingIsAppended', inject(function($rootScope, $compile) { + var a = $compile("<a href='http://s/{{abc}}' ng:bind-attr='{\"b\":\"{{def}}\"}'></a>")($rootScope); assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr')); })); - it('AttributesAreEvaluated', inject(function($rootScope) { - var a = angular.compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($rootScope); + it('AttributesAreEvaluated', inject(function($rootScope, $compile) { + var a = $compile('<a ng:bind-attr=\'{"a":"a", "b":"a+b={{a+b}}"}\'></a>')($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( '<input type="button" ng:click="person.save()" value="Apply">')($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('<input type="image" ng:click="action()">')($rootScope); + var element = $compile('<input type="image" ng:click="action()">')($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('<button ng:click="person.save()">Apply</button>')($rootScope); + var element = $compile('<button ng:click="person.save()">Apply</button>')($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( '<ul>' + '<LI ng:repeat="item in model.items" ng:bind="item.a"></LI>' + '</ul>')($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( '<ul>' + '<LI ng:repeat="item in model.items"><span ng:bind="item.a"></span></li>' + '</ul>')($rootScope); @@ -189,8 +189,8 @@ describe('Binder', function() { assertTrue(html.indexOf('action="foo();"') > 0 ); }); - it('RepeaterAdd', inject(function($rootScope) { - var element = angular.compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($rootScope); + it('RepeaterAdd', inject(function($rootScope, $compile) { + var element = $compile('<div><input type="text" ng:model="item.x" ng:repeat="item in items"></div>')($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('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope); + it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', inject(function($rootScope, $compile) { + var element = $compile('<div><div ng:repeat="i in items">{{i}}</div></div>')($rootScope); var items = {}; $rootScope.items = items; @@ -225,8 +225,8 @@ describe('Binder', function() { function(service){ service('$exceptionHandler', $exceptionHandlerMockFactory); }, - function($rootScope, $exceptionHandler) { - angular.compile('<div>{{error.throw()}}</div>', null, true)($rootScope); + function($rootScope, $exceptionHandler, $compile) { + $compile('<div>{{error.throw()}}</div>', 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('<div attr="before {{error.throw()}} after"></div>', null, true)($rootScope); + }, function($rootScope, $exceptionHandler, $compile) { + $compile('<div attr="before {{error.throw()}} after"></div>', 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( '<div>' + '<div ng:repeat="m in model" name="{{m.name}}">' + '<ul name="{{i}}" ng:repeat="i in m.item"></ul>' + @@ -290,8 +290,8 @@ describe('Binder', function() { '</div></div>', sortedHtml(element)); })); - it('HideBindingExpression', inject(function($rootScope) { - var element = angular.compile('<div ng:hide="hidden == 3"/>')($rootScope); + it('HideBindingExpression', inject(function($rootScope, $compile) { + var element = $compile('<div ng:hide="hidden == 3"/>')($rootScope); $rootScope.hidden = 3; $rootScope.$apply(); @@ -304,8 +304,8 @@ describe('Binder', function() { assertVisible(element); })); - it('HideBinding', inject(function($rootScope) { - var element = angular.compile('<div ng:hide="hidden"/>')($rootScope); + it('HideBinding', inject(function($rootScope, $compile) { + var element = $compile('<div ng:hide="hidden"/>')($rootScope); $rootScope.hidden = 'true'; $rootScope.$apply(); @@ -323,8 +323,8 @@ describe('Binder', function() { assertVisible(element); })); - it('ShowBinding', inject(function($rootScope) { - var element = angular.compile('<div ng:show="show"/>')($rootScope); + it('ShowBinding', inject(function($rootScope, $compile) { + var element = $compile('<div ng:show="show"/>')($rootScope); $rootScope.show = 'true'; $rootScope.$apply(); @@ -343,8 +343,8 @@ describe('Binder', function() { })); - it('BindClass', inject(function($rootScope) { - var element = angular.compile('<div ng:class="clazz"/>')($rootScope); + it('BindClass', inject(function($rootScope, $compile) { + var element = $compile('<div ng:class="clazz"/>')($rootScope); $rootScope.clazz = 'testClass'; $rootScope.$apply(); @@ -357,8 +357,8 @@ describe('Binder', function() { assertEquals('<div class="a b" ng:class="clazz"></div>', sortedHtml(element)); })); - it('BindClassEvenOdd', inject(function($rootScope) { - var element = angular.compile( + it('BindClassEvenOdd', inject(function($rootScope, $compile) { + var element = $compile( '<div>' + '<div ng:repeat="i in [0,1]" ng:class-even="\'e\'" ng:class-odd="\'o\'"></div>' + '</div>')($rootScope); @@ -374,8 +374,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('BindStyle', inject(function($rootScope) { - var element = angular.compile('<div ng:style="style"/>')($rootScope); + it('BindStyle', inject(function($rootScope, $compile) { + var element = $compile('<div ng:style="style"/>')($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('<a ng:click="action()">Add Phone</a>')($rootScope); + function($rootScope, $exceptionHandler, $compile) { + var input = $compile('<a ng:click="action()">Add Phone</a>')($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( "<div>{{a}}" + "<div ng:non-bindable>{{a}}</div>" + "<div ng:non-bindable=''>{{b}}</div>" + @@ -412,8 +412,8 @@ describe('Binder', function() { assertEquals('123{{a}}{{b}}{{c}}', element.text()); })); - it('ShouldTemplateBindPreElements', inject(function ($rootScope) { - var element = angular.compile('<pre>Hello {{name}}!</pre>')($rootScope); + it('ShouldTemplateBindPreElements', inject(function ($rootScope, $compile) { + var element = $compile('<pre>Hello {{name}}!</pre>')($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( '<select ng:model="foo">' + '<option selected="true">{{a}}</option>' + '<option value="">{{b}}</option>' + @@ -446,8 +446,8 @@ describe('Binder', function() { expect(optionC.text()).toEqual('C'); })); - it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope) { - var element = angular.compile( + it('DeleteAttributeIfEvaluatesFalse', inject(function($rootScope, $compile) { + var element = $compile( '<div>' + '<input ng:model="a0" ng:bind-attr="{disabled:\'{{true}}\'}">' + '<input ng:model="a1" ng:bind-attr="{disabled:\'{{false}}\'}">' + @@ -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( '<div>' + '<input type="button" ng:click="greeting=\'ABC\'"/>' + '<input type="button" ng:click=":garbage:"/>' + @@ -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( '<div>' + '<input type="radio" ng:model="sex" value="female">' + '<input type="radio" ng:model="sex" value="male">' + @@ -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( '<ul>' + '<li ng:repeat="(k,v) in {a:0,b:1}" ng:bind=\"k + v\"></li>' + '</ul>')($rootScope); @@ -530,8 +530,8 @@ describe('Binder', function() { sortedHtml(element)); })); - it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope) { - var element = angular.compile('<div ng:bind="name"></div>')($rootScope); + it('ItShouldFireChangeListenersBeforeUpdate', inject(function($rootScope, $compile) { + var element = $compile('<div ng:bind="name"></div>')($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('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope); + it('ItShouldHandleMultilineBindings', inject(function($rootScope, $compile) { + var element = $compile('<div>{{\n 1 \n + \n 2 \n}}</div>')($rootScope); $rootScope.$apply(); assertEquals("3", element.text()); })); |
