diff options
| author | Misko Hevery | 2011-08-10 13:15:43 -0700 |
|---|---|---|
| committer | Misko Hevery | 2011-08-12 15:47:47 -0700 |
| commit | 42062dab34192d2cb9ed66a720c0f791408c61c0 (patch) | |
| tree | ca85b56f12dd0138dbe3d7f1346c4125d64e09a5 /test | |
| parent | 1c9fc1e1dec67c8c05f02da1e0853439238c4d8e (diff) | |
| download | angular.js-42062dab34192d2cb9ed66a720c0f791408c61c0.tar.bz2 | |
refactor(scope): remove $flush/$observe ng:eval/ng:eval-order
Diffstat (limited to 'test')
| -rw-r--r-- | test/AngularSpec.js | 8 | ||||
| -rw-r--r-- | test/BinderSpec.js | 8 | ||||
| -rw-r--r-- | test/CompilerSpec.js | 23 | ||||
| -rw-r--r-- | test/ScenarioSpec.js | 6 | ||||
| -rw-r--r-- | test/ScopeSpec.js | 176 | ||||
| -rw-r--r-- | test/directivesSpec.js | 91 | ||||
| -rw-r--r-- | test/markupSpec.js | 30 | ||||
| -rw-r--r-- | test/service/cookieStoreSpec.js | 6 | ||||
| -rw-r--r-- | test/service/cookiesSpec.js | 16 | ||||
| -rw-r--r-- | test/service/locationSpec.js | 4 | ||||
| -rw-r--r-- | test/service/routeSpec.js | 6 | ||||
| -rw-r--r-- | test/service/updateViewSpec.js | 63 | ||||
| -rw-r--r-- | test/service/xhr.cacheSpec.js | 2 | ||||
| -rw-r--r-- | test/widgetsSpec.js | 150 |
14 files changed, 184 insertions, 405 deletions
diff --git a/test/AngularSpec.js b/test/AngularSpec.js index abb34f3e..cbafa54c 100644 --- a/test/AngularSpec.js +++ b/test/AngularSpec.js @@ -551,7 +551,7 @@ describe('angular', function(){ it('should link to existing node and create scope', function(){ template = angular.element('<div>{{greeting = "hello world"}}</div>'); scope = angular.compile(template)(); - scope.$flush(); + scope.$digest(); expect(template.text()).toEqual('hello world'); expect(scope.greeting).toEqual('hello world'); }); @@ -560,7 +560,7 @@ describe('angular', function(){ scope = angular.scope(); template = angular.element('<div>{{greeting = "hello world"}}</div>'); angular.compile(template)(scope); - scope.$flush(); + scope.$digest(); expect(template.text()).toEqual('hello world'); expect(scope).toEqual(scope); }); @@ -575,7 +575,7 @@ describe('angular', function(){ templateFn(scope, function(clone){ templateClone = clone; }); - scope.$flush(); + scope.$digest(); expect(template.text()).toEqual(''); expect(scope.$element.text()).toEqual('hello world'); @@ -586,7 +586,7 @@ describe('angular', function(){ it('should link to cloned node and create scope', function(){ scope = angular.scope(); template = jqLite('<div>{{greeting = "hello world"}}</div>'); - angular.compile(template)(scope, noop).$flush(); + angular.compile(template)(scope, noop).$digest(); expect(template.text()).toEqual(''); expect(scope.$element.text()).toEqual('hello world'); expect(scope.greeting).toEqual('hello world'); diff --git a/test/BinderSpec.js b/test/BinderSpec.js index a84fe68a..ecfe0682 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -54,8 +54,8 @@ describe('Binder', function(){ }); it('BindUpdate', function(){ - var scope = this.compile('<div ng:eval="a=123"/>'); - scope.$flush(); + var scope = this.compile('<div ng:init="a=123"/>'); + scope.$digest(); assertEquals(123, scope.a); }); @@ -284,6 +284,7 @@ describe('Binder', function(){ assertEquals(['ErrorMsg1'], errorLogs.shift()); scope.error['throw'] = function(){throw "MyError";}; + errorLogs.length = 0; scope.$apply(); span = childNode(doc, 0); assertTrue(span.hasClass('ng-exception')); @@ -309,8 +310,9 @@ describe('Binder', function(){ 'throw': function(){throw new Error("ErrorMsg" + (++count));} }; scope.$apply(); - expect(errorLogs.length).toMatch(1); + expect(errorLogs.length).not.toEqual(0); expect(errorLogs.shift()).toMatch(/ErrorMsg1/); + errorLogs.length = 0; scope.error['throw'] = function(){ return 'X';}; scope.$apply(); diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js index 90afbaff..8f86e99a 100644 --- a/test/CompilerSpec.js +++ b/test/CompilerSpec.js @@ -15,7 +15,7 @@ describe('compiler', function(){ observe: function(expression, element){ return function() { - this.$observe(expression, function(scope, val){ + this.$watch(expression, function(scope, val){ if (val) log += ":" + val; }); @@ -76,13 +76,13 @@ describe('compiler', function(){ it('should observe scope', function(){ scope = compile('<span observe="name">'); expect(log).toEqual(""); - scope.$flush(); + scope.$digest(); scope.name = 'misko'; - scope.$flush(); - scope.$flush(); + scope.$digest(); + scope.$digest(); scope.name = 'adam'; - scope.$flush(); - scope.$flush(); + scope.$digest(); + scope.$digest(); expect(log).toEqual(":misko:adam"); }); @@ -100,18 +100,21 @@ describe('compiler', function(){ element.removeAttr("duplicate"); var linker = this.compile(element); return function(marker) { - this.$observe(function() { + this.$watch('value', function() { var scope = linker(angular.scope(), noop); marker.after(scope.$element); }); }; }; scope = compile('before<span duplicate="expr">x</span>after'); - scope.$flush(); + scope.value = 1; + scope.$digest(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span>after</div>'); - scope.$flush(); + scope.value = 2; + scope.$digest(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span>after</div>'); - scope.$flush(); + scope.value = 3; + scope.$digest(); expect(sortedHtml(scope.$element)).toEqual('<div>before<#comment></#comment><span>x</span><span>x</span><span>x</span>after</div>'); }); diff --git a/test/ScenarioSpec.js b/test/ScenarioSpec.js index ce8b0dec..e91e0b98 100644 --- a/test/ScenarioSpec.js +++ b/test/ScenarioSpec.js @@ -15,20 +15,20 @@ describe("ScenarioSpec: Compilation", function(){ it("should compile dom node and return scope", function(){ var node = jqLite('<div ng:init="a=1">{{b=a+1}}</div>')[0]; scope = angular.compile(node)(); - scope.$flush(); + scope.$digest(); expect(scope.a).toEqual(1); expect(scope.b).toEqual(2); }); it("should compile jQuery node and return scope", function(){ scope = compile(jqLite('<div>{{a=123}}</div>'))(); - scope.$flush(); + scope.$digest(); expect(jqLite(scope.$element).text()).toEqual('123'); }); it("should compile text node and return scope", function(){ scope = angular.compile('<div>{{a=123}}</div>')(); - scope.$flush(); + scope.$digest(); expect(jqLite(scope.$element).text()).toEqual('123'); }); }); diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 6105df21..5a14abd6 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -5,9 +5,6 @@ describe('Scope', function(){ beforeEach(function(){ root = createScope(angular.service, { - $updateView: function(){ - root.$flush(); - }, '$exceptionHandler': $exceptionHandlerMockFactory() }); mockHandler = root.$service('$exceptionHandler'); @@ -108,6 +105,9 @@ describe('Scope', function(){ it('should watch and fire on simple property change', function(){ var spy = jasmine.createSpy(); root.$watch('name', spy); + root.$digest(); + spy.reset(); + expect(spy).not.wasCalled(); root.$digest(); expect(spy).not.wasCalled(); @@ -120,6 +120,9 @@ describe('Scope', function(){ it('should watch and fire on expression change', function(){ var spy = jasmine.createSpy(); root.$watch('name.first', spy); + root.$digest(); + spy.reset(); + root.name = {}; expect(spy).not.wasCalled(); root.$digest(); @@ -170,6 +173,8 @@ describe('Scope', function(){ root.$watch('c', function(self, v){self.d = v; log+='c'; }); root.$watch('b', function(self, v){self.c = v; log+='b'; }); root.$watch('a', function(self, v){self.b = v; log+='a'; }); + root.$digest(); + log = ''; root.a = 1; expect(root.$digest()).toEqual(3); expect(root.b).toEqual(1); @@ -204,22 +209,13 @@ describe('Scope', function(){ root.a = 1; root.$watch('a', function(){ log += 'a'; }); root.$watch('b', function(){ log += 'b'; }); - expect(log).toEqual(''); + root.$digest(); + log = ''; expect(root.$digest()).toEqual(0); expect(log).toEqual(''); }); - it('should return the listener to force a initial watch', function(){ - var log = ''; - root.a = 1; - root.$watch('a', function(scope, o1, o2){ log += scope.a + ':' + (o1 == o2 == 1) ; })(); - expect(log).toEqual('1:true'); - expect(root.$digest()).toEqual(0); - expect(log).toEqual('1:true'); - }); - - it('should watch objects', function(){ var log = ''; root.a = []; @@ -227,7 +223,7 @@ describe('Scope', function(){ root.$watch('a', function(){ log +='.';}); root.$watch('b', function(){ log +='!';}); root.$digest(); - expect(log).toEqual(''); + log = ''; root.a.push({}); root.b.name = ''; @@ -243,9 +239,6 @@ describe('Scope', function(){ expect(function(){ root.$digest(); }).toThrow('$digest already in progress'); - expect(function(){ - root.$flush(); - }).toThrow('$digest already in progress'); callCount++; }); root.name = 'a'; @@ -255,138 +248,6 @@ describe('Scope', function(){ }); - describe('$observe/$flush', function(){ - it('should register simple property observer and fire on change', function(){ - var spy = jasmine.createSpy(); - root.$observe('name', spy); - expect(spy).not.wasCalled(); - root.$flush(); - expect(spy).wasCalled(); - expect(spy.mostRecentCall.args[0]).toEqual(root); - expect(spy.mostRecentCall.args[1]).toEqual(undefined); - expect(spy.mostRecentCall.args[2].toString()).toEqual(NaN.toString()); - root.name = 'misko'; - root.$flush(); - expect(spy).wasCalledWith(root, 'misko', undefined); - }); - - - it('should register expression observers and fire them on change', function(){ - var spy = jasmine.createSpy(); - root.$observe('name.first', spy); - root.name = {}; - expect(spy).not.wasCalled(); - root.$flush(); - expect(spy).wasCalled(); - root.name.first = 'misko'; - root.$flush(); - expect(spy).wasCalled(); - }); - - - it('should delegate exceptions', function(){ - root.$observe('a', function(){throw new Error('abc');}); - root.a = 1; - root.$flush(); - expect(mockHandler.errors[0].message).toEqual('abc'); - $logMock.error.logs.shift(); - }); - - - it('should fire observers in order of addition', function(){ - // this is not an external guarantee, just our own sanity - var log = ''; - root.$observe('a', function(){ log += 'a'; }); - root.$observe('b', function(){ log += 'b'; }); - root.$observe('c', function(){ log += 'c'; }); - root.a = root.b = root.c = 1; - root.$flush(); - expect(log).toEqual('abc'); - }); - - - it('should delegate $flush to children in addition order', function(){ - // this is not an external guarantee, just our own sanity - var log = ''; - var childA = root.$new(); - var childB = root.$new(); - var childC = root.$new(); - childA.$observe('a', function(){ log += 'a'; }); - childB.$observe('b', function(){ log += 'b'; }); - childC.$observe('c', function(){ log += 'c'; }); - childA.a = childB.b = childC.c = 1; - root.$flush(); - expect(log).toEqual('abc'); - }); - - - it('should fire observers once at beggining and on change', function(){ - var log = ''; - root.$observe('c', function(self, v){self.d = v; log += 'c';}); - root.$observe('b', function(self, v){self.c = v; log += 'b';}); - root.$observe('a', function(self, v){self.b = v; log += 'a';}); - root.a = 1; - root.$flush(); - expect(root.b).toEqual(1); - expect(log).toEqual('cba'); - root.$flush(); - expect(root.c).toEqual(1); - expect(log).toEqual('cbab'); - root.$flush(); - expect(root.d).toEqual(1); - expect(log).toEqual('cbabc'); - }); - - - it('should fire on initial observe', function(){ - var log = ''; - root.a = 1; - root.$observe('a', function(){ log += 'a'; }); - root.$observe('b', function(){ log += 'b'; }); - expect(log).toEqual(''); - root.$flush(); - expect(log).toEqual('ab'); - }); - - - it('should observe objects', function(){ - var log = ''; - root.a = []; - root.b = {}; - root.$observe('a', function(){ log +='.';}); - root.$observe('a', function(){ log +='!';}); - root.$flush(); - expect(log).toEqual('.!'); - - root.$flush(); - expect(log).toEqual('.!'); - - root.a.push({}); - root.b.name = ''; - - root.$digest(); - expect(log).toEqual('.!'); - }); - - - it('should prevent recursion', function(){ - var callCount = 0; - root.$observe('name', function(){ - expect(function(){ - root.$digest(); - }).toThrow('$flush already in progress'); - expect(function(){ - root.$flush(); - }).toThrow('$flush already in progress'); - callCount++; - }); - root.name = 'a'; - root.$flush(); - expect(callCount).toEqual(1); - }); - }); - - describe('$destroy', function(){ var first, middle, last, log; @@ -401,6 +262,7 @@ describe('Scope', function(){ middle.$watch(function(){ log += '2';}); last.$watch(function(){ log += '3';}); + root.$digest(); log = ''; }); @@ -450,9 +312,8 @@ describe('Scope', function(){ var log = ''; var child = root.$new(); root.$watch('a', function(scope, a){ log += '1'; }); - root.$observe('a', function(scope, a){ log += '2'; }); child.$apply('$parent.a=0'); - expect(log).toEqual('12'); + expect(log).toEqual('1'); }); @@ -460,25 +321,24 @@ describe('Scope', function(){ var log = ''; var child = root.$new(); root.$watch('a', function(scope, a){ log += '1'; }); - root.$observe('a', function(scope, a){ log += '2'; }); root.a = 0; child.$apply(function(){ throw new Error('MyError'); }); - expect(log).toEqual('12'); + expect(log).toEqual('1'); expect(mockHandler.errors[0].message).toEqual('MyError'); $logMock.error.logs.shift(); }); describe('exceptions', function(){ - var $exceptionHandler, $updateView, log; + var $exceptionHandler, log; beforeEach(function(){ log = ''; $exceptionHandler = jasmine.createSpy('$exceptionHandler'); - $updateView = jasmine.createSpy('$updateView'); root.$service = function(name) { - return {$updateView:$updateView, $exceptionHandler:$exceptionHandler}[name]; + return {$exceptionHandler:$exceptionHandler}[name]; }; root.$watch(function(){ log += '$digest;'; }); + root.$digest(); log = ''; }); @@ -490,7 +350,6 @@ describe('Scope', function(){ })).toEqual('abc'); expect(log).toEqual('$digest;'); expect($exceptionHandler).not.wasCalled(); - expect($updateView).wasCalled(); }); @@ -499,7 +358,6 @@ describe('Scope', function(){ root.$apply(function(){ throw error; }); expect(log).toEqual('$digest;'); expect($exceptionHandler).wasCalledWith(error); - expect($updateView).wasCalled(); }); }); }); diff --git a/test/directivesSpec.js b/test/directivesSpec.js index a05861ae..1a02e318 100644 --- a/test/directivesSpec.js +++ b/test/directivesSpec.js @@ -20,20 +20,12 @@ describe("directive", function(){ expect(scope.a).toEqual(123); }); - it("should ng:eval", function() { - var scope = compile('<div ng:init="a=0" ng:eval="a = a + 1"></div>'); - scope.$flush(); - expect(scope.a).toEqual(1); - scope.$flush(); - expect(scope.a).toEqual(2); - }); - describe('ng:bind', function(){ it('should set text', function() { var scope = compile('<div ng:bind="a"></div>'); expect(element.text()).toEqual(''); scope.a = 'misko'; - scope.$flush(); + scope.$digest(); expect(element.hasClass('ng-binding')).toEqual(true); expect(element.text()).toEqual('misko'); }); @@ -41,24 +33,24 @@ describe("directive", function(){ it('should set text to blank if undefined', function() { var scope = compile('<div ng:bind="a"></div>'); scope.a = 'misko'; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko'); scope.a = undefined; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual(''); }); it('should set html', function() { var scope = compile('<div ng:bind="html|html"></div>'); scope.html = '<div unknown>hello</div>'; - scope.$flush(); + scope.$digest(); expect(lowercase(element.html())).toEqual('<div>hello</div>'); }); it('should set unsafe html', function() { var scope = compile('<div ng:bind="html|html:\'unsafe\'"></div>'); scope.html = '<div onclick="">hello</div>'; - scope.$flush(); + scope.$digest(); expect(lowercase(element.html())).toEqual('<div onclick="">hello</div>'); }); @@ -67,7 +59,7 @@ describe("directive", function(){ return jqLite('<a>hello</a>'); }; var scope = compile('<div ng:bind="0|myElement"></div>'); - scope.$flush(); + scope.$digest(); expect(lowercase(element.html())).toEqual('<a>hello</a>'); }); @@ -77,14 +69,14 @@ describe("directive", function(){ return 'HELLO'; }; var scope = compile('<div>before<div ng:bind="0|myFilter"></div>after</div>'); - scope.$flush(); + scope.$digest(); expect(sortedHtml(scope.$element)).toEqual('<div>before<div class="filter" ng:bind="0|myFilter">HELLO</div>after</div>'); }); it('should suppress rendering of falsy values', function(){ var scope = compile('<div>{{ null }}{{ undefined }}{{ "" }}-{{ 0 }}{{ false }}</div>'); - scope.$flush(); + scope.$digest(); expect(scope.$element.text()).toEqual('-0false'); }); @@ -94,19 +86,19 @@ describe("directive", function(){ it('should ng:bind-template', function() { var scope = compile('<div ng:bind-template="Hello {{name}}!"></div>'); scope.name = 'Misko'; - scope.$flush(); + scope.$digest(); expect(element.hasClass('ng-binding')).toEqual(true); expect(element.text()).toEqual('Hello Misko!'); }); it('should have $element set to current bind element', function(){ - var innerText = 'blank'; + var innerText; angularFilter.myFilter = function(text){ - innerText = this.$element.text(); + innerText = innerText || this.$element.text(); return text; }; var scope = compile('<div>before<span ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</span>after</div>'); - scope.$flush(); + scope.$digest(); expect(scope.$element.text()).toEqual("beforeHELLOafter"); expect(innerText).toEqual('INNER'); }); @@ -116,14 +108,14 @@ describe("directive", function(){ describe('ng:bind-attr', function(){ it('should bind attributes', function(){ var scope = compile('<div ng:bind-attr="{src:\'http://localhost/mysrc\', alt:\'myalt\'}"/>'); - scope.$flush(); + scope.$digest(); expect(element.attr('src')).toEqual('http://localhost/mysrc'); expect(element.attr('alt')).toEqual('myalt'); }); it('should not pretty print JSON in attributes', function(){ var scope = compile('<img alt="{{ {a:1} }}"/>'); - scope.$flush(); + scope.$digest(); expect(element.attr('alt')).toEqual('{"a":1}'); }); }); @@ -138,7 +130,7 @@ describe("directive", function(){ scope.disabled = true; scope.readonly = true; scope.checked = true; - scope.$flush(); + scope.$digest(); expect(input.disabled).toEqual(true); expect(input.readOnly).toEqual(true); @@ -148,7 +140,7 @@ describe("directive", function(){ describe('ng:click', function(){ it('should get called on a click', function(){ var scope = compile('<div ng:click="clicked = true"></div>'); - scope.$flush(); + scope.$digest(); expect(scope.clicked).toBeFalsy(); browserTrigger(element, 'click'); @@ -157,7 +149,7 @@ describe("directive", function(){ it('should stop event propagation', function() { var scope = compile('<div ng:click="outer = true"><div ng:click="inner = true"></div></div>'); - scope.$flush(); + scope.$digest(); expect(scope.outer).not.toBeDefined(); expect(scope.inner).not.toBeDefined(); @@ -175,7 +167,7 @@ describe("directive", function(){ var scope = compile('<form action="" ng:submit="submitted = true">' + '<input type="submit"/>' + '</form>'); - scope.$flush(); + scope.$digest(); expect(scope.submitted).not.toBeDefined(); browserTrigger(element.children()[0]); @@ -187,18 +179,18 @@ describe("directive", function(){ it('should add new and remove old classes dynamically', function() { var scope = compile('<div class="existing" ng:class="dynClass"></div>'); scope.dynClass = 'A'; - scope.$flush(); + scope.$digest(); expect(element.hasClass('existing')).toBe(true); expect(element.hasClass('A')).toBe(true); scope.dynClass = 'B'; - scope.$flush(); + scope.$digest(); expect(element.hasClass('existing')).toBe(true); expect(element.hasClass('A')).toBe(false); expect(element.hasClass('B')).toBe(true); delete scope.dynClass; - scope.$flush(); + scope.$digest(); expect(element.hasClass('existing')).toBe(true); expect(element.hasClass('A')).toBe(false); expect(element.hasClass('B')).toBe(false); @@ -206,7 +198,7 @@ describe("directive", function(){ it('should support adding multiple classes', function(){ var scope = compile('<div class="existing" ng:class="[\'A\', \'B\']"></div>'); - scope.$flush(); + scope.$digest(); expect(element.hasClass('existing')).toBeTruthy(); expect(element.hasClass('A')).toBeTruthy(); expect(element.hasClass('B')).toBeTruthy(); @@ -216,7 +208,7 @@ describe("directive", function(){ it('should ng:class odd/even', function(){ var scope = compile('<ul><li ng:repeat="i in [0,1]" class="existing" ng:class-odd="\'odd\'" ng:class-even="\'even\'"></li><ul>'); - scope.$flush(); + scope.$digest(); var e1 = jqLite(element[0].childNodes[1]); var e2 = jqLite(element[0].childNodes[2]); expect(e1.hasClass('existing')).toBeTruthy(); @@ -228,32 +220,32 @@ describe("directive", function(){ describe('ng:style', function(){ it('should set', function(){ var scope = compile('<div ng:style="{height: \'40px\'}"></div>'); - scope.$flush(); + scope.$digest(); expect(element.css('height')).toEqual('40px'); }); it('should silently ignore undefined style', function() { var scope = compile('<div ng:style="myStyle"></div>'); - scope.$flush(); + scope.$digest(); expect(element.hasClass('ng-exception')).toBeFalsy(); }); it('should preserve and remove previous style', function(){ var scope = compile('<div style="height: 10px;" ng:style="myStyle"></div>'); - scope.$flush(); + scope.$digest(); expect(getStyle(element)).toEqual({height: '10px'}); scope.myStyle = {height: '20px', width: '10px'}; - scope.$flush(); + scope.$digest(); expect(getStyle(element)).toEqual({height: '20px', width: '10px'}); scope.myStyle = {}; - scope.$flush(); + scope.$digest(); expect(getStyle(element)).toEqual({height: '10px'}); }); }); it('should silently ignore undefined ng:style', function() { var scope = compile('<div ng:style="myStyle"></div>'); - scope.$flush(); + scope.$digest(); expect(element.hasClass('ng-exception')).toBeFalsy(); }); @@ -263,10 +255,10 @@ describe("directive", function(){ var element = jqLite('<div ng:show="exp"></div>'), scope = compile(element); - scope.$flush(); + scope.$digest(); expect(isCssVisible(element)).toEqual(false); scope.exp = true; - scope.$flush(); + scope.$digest(); expect(isCssVisible(element)).toEqual(true); }); @@ -277,7 +269,7 @@ describe("directive", function(){ expect(isCssVisible(element)).toBe(false); scope.exp = true; - scope.$flush(); + scope.$digest(); expect(isCssVisible(element)).toBe(true); }); }); @@ -289,7 +281,7 @@ describe("directive", function(){ expect(isCssVisible(element)).toBe(true); scope.exp = true; - scope.$flush(); + scope.$digest(); expect(isCssVisible(element)).toBe(false); }); }); @@ -339,25 +331,10 @@ describe("directive", function(){ expect(scope.greeter.greeting).toEqual('hello'); expect(scope.childGreeter.greeting).toEqual('hey'); expect(scope.childGreeter.$parent.greeting).toEqual('hello'); - scope.$flush(); + scope.$digest(); expect(scope.$element.text()).toEqual('hey dude!'); }); }); - //TODO(misko): this needs to be deleted when ng:eval-order is gone - it('should eval things according to ng:eval-order', function(){ - var scope = compile( - '<div ng:init="log=\'\'">' + - '{{log = log + \'e\'}}' + - '<span ng:eval-order="first" ng:eval="log = log + \'a\'">' + - '{{log = log + \'b\'}}' + - '<span src="{{log = log + \'c\'}}"></span>' + - '<span bind-template="{{log = log + \'d\'}}"></span>' + - '</span>' + - '</div>'); - scope.$flush(); - expect(scope.log).toEqual('abcde'); - }); - }); diff --git a/test/markupSpec.js b/test/markupSpec.js index ab8b4c74..36861e17 100644 --- a/test/markupSpec.js +++ b/test/markupSpec.js @@ -21,16 +21,16 @@ describe("markups", function(){ compile('<div>hello {{name}}!</div>'); expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name"></span>!</div>'); scope.name = 'Misko'; - scope.$flush(); + scope.$digest(); expect(sortedHtml(element)).toEqual('<div>hello <span ng:bind="name">Misko</span>!</div>'); }); it('should translate {{}} in terminal nodes', function(){ compile('<select name="x"><option value="">Greet {{name}}!</option></select>'); - scope.$flush(); + scope.$digest(); expect(sortedHtml(element).replace(' selected="true"', '')).toEqual('<select name="x"><option ng:bind-template="Greet {{name}}!">Greet !</option></select>'); scope.name = 'Misko'; - scope.$flush(); + scope.$digest(); expect(sortedHtml(element).replace(' selected="true"', '')).toEqual('<select name="x"><option ng:bind-template="Greet {{name}}!">Greet Misko!</option></select>'); }); @@ -38,7 +38,7 @@ describe("markups", function(){ compile('<div src="http://server/{{path}}.png"/>'); expect(element.attr('ng:bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}'); scope.path = 'a/b'; - scope.$flush(); + scope.$digest(); expect(element.attr('src')).toEqual("http://server/a/b.png"); }); @@ -95,57 +95,57 @@ describe("markups", function(){ it('should bind disabled', function() { compile('<button ng:disabled="{{isDisabled}}">Button</button>'); scope.isDisabled = false; - scope.$flush(); + scope.$digest(); expect(element.attr('disabled')).toBeFalsy(); scope.isDisabled = true; - scope.$flush(); + scope.$digest(); expect(element.attr('disabled')).toBeTruthy(); }); it('should bind checked', function() { compile('<input type="checkbox" ng:checked="{{isChecked}}" />'); scope.isChecked = false; - scope.$flush(); + scope.$digest(); expect(element.attr('checked')).toBeFalsy(); scope.isChecked=true; - scope.$flush(); + scope.$digest(); expect(element.attr('checked')).toBeTruthy(); }); it('should bind selected', function() { compile('<select><option value=""></option><option ng:selected="{{isSelected}}">Greetings!</option></select>'); scope.isSelected=false; - scope.$flush(); + scope.$digest(); expect(element.children()[1].selected).toBeFalsy(); scope.isSelected=true; - scope.$flush(); + scope.$digest(); expect(element.children()[1].selected).toBeTruthy(); }); it('should bind readonly', function() { compile('<input type="text" ng:readonly="{{isReadonly}}" />'); scope.isReadonly=false; - scope.$flush(); + scope.$digest(); expect(element.attr('readOnly')).toBeFalsy(); scope.isReadonly=true; - scope.$flush(); + scope.$digest(); expect(element.attr('readOnly')).toBeTruthy(); }); it('should bind multiple', function() { compile('<select ng:multiple="{{isMultiple}}"></select>'); scope.isMultiple=false; - scope.$flush(); + scope.$digest(); expect(element.attr('multiple')).toBeFalsy(); scope.isMultiple='multiple'; - scope.$flush(); + scope.$digest(); expect(element.attr('multiple')).toBeTruthy(); }); it('should bind src', function() { compile('<div ng:src="{{url}}" />'); scope.url = 'http://localhost/'; - scope.$flush(); + scope.$digest(); expect(element.attr('src')).toEqual('http://localhost/'); }); diff --git a/test/service/cookieStoreSpec.js b/test/service/cookieStoreSpec.js index 75be924c..fa4f3ceb 100644 --- a/test/service/cookieStoreSpec.js +++ b/test/service/cookieStoreSpec.js @@ -16,7 +16,7 @@ describe('$cookieStore', function() { it('should serialize objects to json', function() { $cookieStore.put('objectCookie', {id: 123, name: 'blah'}); - scope.$flush(); + scope.$digest(); expect($browser.cookies()).toEqual({'objectCookie': '{"id":123,"name":"blah"}'}); }); @@ -30,12 +30,12 @@ describe('$cookieStore', function() { it('should delete objects from the store when remove is called', function() { $cookieStore.put('gonner', { "I'll":"Be Back"}); - scope.$flush(); //force eval in test + scope.$digest(); //force eval in test $browser.poll(); expect($browser.cookies()).toEqual({'gonner': '{"I\'ll":"Be Back"}'}); $cookieStore.remove('gonner'); - scope.$flush(); + scope.$digest(); expect($browser.cookies()).toEqual({}); }); }); diff --git a/test/service/cookiesSpec.js b/test/service/cookiesSpec.js index cc667b56..782cee72 100644 --- a/test/service/cookiesSpec.js +++ b/test/service/cookiesSpec.js @@ -38,13 +38,13 @@ describe('$cookies', function() { it('should create or update a cookie when a value is assigned to a property', function() { scope.$cookies.oatmealCookie = 'nom nom'; - scope.$flush(); + scope.$digest(); expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); scope.$cookies.oatmealCookie = 'gone'; - scope.$flush(); + scope.$digest(); expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie': 'gone'}); @@ -56,7 +56,7 @@ describe('$cookies', function() { scope.$cookies.nullVal = null; scope.$cookies.undefVal = undefined; scope.$cookies.preexisting = function(){}; - scope.$flush(); + scope.$digest(); expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'}); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); }); @@ -64,13 +64,13 @@ describe('$cookies', function() { it('should remove a cookie when a $cookies property is deleted', function() { scope.$cookies.oatmealCookie = 'nom nom'; - scope.$flush(); + scope.$digest(); $browser.poll(); expect($browser.cookies()). toEqual({'preexisting': 'oldCookie', 'oatmealCookie':'nom nom'}); delete scope.$cookies.oatmealCookie; - scope.$flush(); + scope.$digest(); expect($browser.cookies()).toEqual({'preexisting': 'oldCookie'}); }); @@ -85,16 +85,16 @@ describe('$cookies', function() { //drop if no previous value scope.$cookies.longCookie = longVal; - scope.$flush(); + scope.$digest(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie'}); //reset if previous value existed scope.$cookies.longCookie = 'shortVal'; - scope.$flush(); + scope.$digest(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'longCookie': 'shortVal'}); scope.$cookies.longCookie = longVal; - scope.$flush(); + scope.$digest(); expect(scope.$cookies).toEqual({'preexisting': 'oldCookie', 'longCookie': 'shortVal'}); }); }); diff --git a/test/service/locationSpec.js b/test/service/locationSpec.js index 73e5e43e..5839b0b6 100644 --- a/test/service/locationSpec.js +++ b/test/service/locationSpec.js @@ -108,7 +108,9 @@ describe('$location', function() { var log = ''; scope.$watch('$location.hash', function(scope){ log += scope.$location.hashPath + ';'; - })(); + }); + expect(log).toEqual(''); + scope.$digest(); expect(log).toEqual(';'); log = ''; diff --git a/test/service/routeSpec.js b/test/service/routeSpec.js index 6c6c0868..bfe201d1 100644 --- a/test/service/routeSpec.js +++ b/test/service/routeSpec.js @@ -71,7 +71,7 @@ describe('$route', function() { $route.when('/foo', {template: 'foo.html'}); $route.onChange(onChangeSpy); - expect($route.current).toBeNull(); + expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); $location.updateHash('/foo'); @@ -94,7 +94,7 @@ describe('$route', function() { $route.when('/foo', {template: 'foo.html'}); $route.otherwise({template: '404.html', controller: NotFoundCtrl}); $route.onChange(onChangeSpy); - expect($route.current).toBeNull(); + expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); $location.updateHash('/unknownRoute'); @@ -164,7 +164,7 @@ describe('$route', function() { $route.when('/baz', {redirectTo: '/bar'}); $route.otherwise({template: '404.html'}); $route.onChange(onChangeSpy); - expect($route.current).toBeNull(); + expect($route.current).toBeUndefined(); expect(onChangeSpy).not.toHaveBeenCalled(); scope.$digest(); //triggers initial route change - match the redirect route diff --git a/test/service/updateViewSpec.js b/test/service/updateViewSpec.js deleted file mode 100644 index d8932d29..00000000 --- a/test/service/updateViewSpec.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; - -describe('$updateView', function() { - var scope, browser, evalCount, $updateView; - - beforeEach(function(){ - browser = new MockBrowser(); - // Pretend that you are real Browser so that we see the delays - browser.isMock = false; - browser.defer = jasmine.createSpy('defer'); - - scope = angular.scope(null, {$browser:browser}); - $updateView = scope.$service('$updateView'); - scope.$observe(function(){ evalCount++; }); - evalCount = 0; - }); - - - afterEach(function(){ - dealoc(scope); - }); - - - it('should eval root scope after a delay', function(){ - $updateView(); - expect(evalCount).toEqual(0); - expect(browser.defer).toHaveBeenCalled(); - expect(browser.defer.mostRecentCall.args[1]).toEqual(25); - browser.defer.mostRecentCall.args[0](); - expect(evalCount).toEqual(1); - }); - - - it('should allow changing of delay time', function(){ - var oldValue = angular.service('$updateView').delay; - angular.service('$updateView').delay = 50; - $updateView(); - expect(evalCount).toEqual(0); - expect(browser.defer).toHaveBeenCalled(); - expect(browser.defer.mostRecentCall.args[1]).toEqual(50); - angular.service('$updateView').delay = oldValue; - }); - - - it('should ignore multiple requests for update', function(){ - $updateView(); - $updateView(); - expect(evalCount).toEqual(0); - expect(browser.defer).toHaveBeenCalled(); - expect(browser.defer.callCount).toEqual(1); - browser.defer.mostRecentCall.args[0](); - expect(evalCount).toEqual(1); - }); - - - it('should update immediatelly in test/mock mode', function(){ - scope = angular.scope(); - scope.$observe(function(){ evalCount++; }); - expect(evalCount).toEqual(0); - scope.$service('$updateView')(); - expect(evalCount).toEqual(1); - }); -}); diff --git a/test/service/xhr.cacheSpec.js b/test/service/xhr.cacheSpec.js index 7bf5d40b..c6b9cfec 100644 --- a/test/service/xhr.cacheSpec.js +++ b/test/service/xhr.cacheSpec.js @@ -126,7 +126,7 @@ describe('$xhr.cache', function() { it('should call eval after callbacks for both cache hit and cache miss execute', function() { - var flushSpy = this.spyOn(scope, '$flush').andCallThrough(); + var flushSpy = this.spyOn(scope, '$digest').andCallThrough(); $browserXhr.expectGET('/url').respond('+'); cache('GET', '/url', null, callback); diff --git a/test/widgetsSpec.js b/test/widgetsSpec.js index 0ca42110..9e8492f1 100644 --- a/test/widgetsSpec.js +++ b/test/widgetsSpec.js @@ -368,7 +368,7 @@ describe("widget", function(){ '</select>'); scope.a = 'foo'; scope.b = 'bar'; - scope.$flush(); + scope.$digest(); expect(scope.$element.text()).toBe('foobarC'); }); @@ -465,7 +465,7 @@ describe("widget", function(){ scope.childScope.name = 'misko'; scope.url = 'myUrl'; scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko'); dealoc(scope); }); @@ -477,12 +477,12 @@ describe("widget", function(){ scope.childScope.name = 'igor'; scope.url = 'myUrl'; scope.$service('$xhr.cache').data.myUrl = {value:'{{name}}'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('igor'); scope.url = undefined; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual(''); dealoc(scope); @@ -492,15 +492,15 @@ describe("widget", function(){ var element = jqLite('<ng:include src="url" scope="this"></ng:include>'); var scope = angular.compile(element)(); scope.url = 'myUrl'; - scope.$service('$xhr.cache').data.myUrl = {value:'{{c=c+1}}'}; - scope.$flush(); + scope.$service('$xhr.cache').data.myUrl = {value:'{{"abc"}}'}; + scope.$digest(); // TODO(misko): because we are using scope==this, the eval gets registered // during the flush phase and hence does not get called. // I don't think passing 'this' makes sense. Does having scope on ng:include makes sense? // should we make scope="this" ilegal? - scope.$flush(); + scope.$digest(); - expect(element.text()).toEqual('1'); + expect(element.text()).toEqual('abc'); dealoc(element); }); @@ -512,7 +512,7 @@ describe("widget", function(){ scope.url = 'myUrl'; scope.$service('$xhr.cache').data.myUrl = {value:'my partial'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('my partial'); expect(scope.loaded).toBe(true); dealoc(element); @@ -526,11 +526,11 @@ describe("widget", function(){ scope.url = 'myUrl'; scope.$service('$xhr.cache').data.myUrl = {value:'my partial'}; - scope.$flush(); + scope.$digest(); expect(scope.$$childHead).toBeTruthy(); scope.url = null; - scope.$flush(); + scope.$digest(); expect(scope.$$childHead).toBeFalsy(); dealoc(element); }); @@ -622,7 +622,7 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}, {name:'C'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); var options = select.find('option'); expect(options.length).toEqual(3); expect(sortedHtml(options[0])).toEqual('<option value="0">A</option>'); @@ -637,7 +637,7 @@ describe("widget", function(){ }); scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; scope.selected = scope.object.red; - scope.$flush(); + scope.$digest(); var options = select.find('option'); expect(options.length).toEqual(3); expect(sortedHtml(options[0])).toEqual('<option value="blue">blue</option>'); @@ -646,7 +646,7 @@ describe("widget", function(){ expect(options[2].selected).toEqual(true); scope.object.azur = '8888FF'; - scope.$flush(); + scope.$digest(); options = select.find('option'); expect(options[3].selected).toEqual(true); }); @@ -654,18 +654,18 @@ describe("widget", function(){ it('should grow list', function(){ createSingleSelect(); scope.values = []; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); // because we add special empty option expect(sortedHtml(select.find('option')[0])).toEqual('<option value="?"></option>'); scope.values.push({name:'A'}); scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); expect(sortedHtml(select.find('option')[0])).toEqual('<option value="0">A</option>'); scope.values.push({name:'B'}); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(sortedHtml(select.find('option')[0])).toEqual('<option value="0">A</option>'); expect(sortedHtml(select.find('option')[1])).toEqual('<option value="1">B</option>'); @@ -675,23 +675,23 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}, {name:'C'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(3); scope.values.pop(); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(sortedHtml(select.find('option')[0])).toEqual('<option value="0">A</option>'); expect(sortedHtml(select.find('option')[1])).toEqual('<option value="1">B</option>'); scope.values.pop(); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); expect(sortedHtml(select.find('option')[0])).toEqual('<option value="0">A</option>'); scope.values.pop(); scope.selected = null; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); // we add back the special empty option }); @@ -699,17 +699,17 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}, {name:'C'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(3); scope.values = [{name:'1'}, {name:'2'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); scope.values = [{name:'A'}, {name:'B'}, {name:'C'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(3); }); @@ -717,11 +717,11 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}, {name:'C'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); scope.values = [{name:'B'}, {name:'C'}, {name:'D'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); var options = select.find('option'); expect(options.length).toEqual(3); expect(sortedHtml(options[0])).toEqual('<option value="0">B</option>'); @@ -732,19 +732,19 @@ describe("widget", function(){ it('should preserve existing options', function(){ createSingleSelect(true); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); scope.values = [{name:'A'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(jqLite(select.find('option')[0]).text()).toEqual('blank'); expect(jqLite(select.find('option')[1]).text()).toEqual('A'); scope.values = []; scope.selected = null; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(1); expect(jqLite(select.find('option')[0]).text()).toEqual('blank'); }); @@ -754,11 +754,11 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); scope.selected = scope.values[1]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('1'); }); @@ -773,7 +773,7 @@ describe("widget", function(){ {name:'D', group:'first'}, {name:'E', group:'second'}]; scope.selected = scope.values[3]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('3'); var first = jqLite(select.find('optgroup')[0]); @@ -791,7 +791,7 @@ describe("widget", function(){ expect(e.text()).toEqual('E'); scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); }); @@ -799,11 +799,11 @@ describe("widget", function(){ createSelect({'name':'selected', 'ng:options':'item.id as item.name for item in values'}); scope.values = [{id:10, name:'A'}, {id:20, name:'B'}]; scope.selected = scope.values[0].id; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); scope.selected = scope.values[1].id; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('1'); }); @@ -814,11 +814,11 @@ describe("widget", function(){ }); scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; scope.selected = 'green'; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('green'); scope.selected = 'blue'; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('blue'); }); @@ -829,11 +829,11 @@ describe("widget", function(){ }); scope.object = {'red':'FF0000', 'green':'00FF00', 'blue':'0000FF'}; scope.selected = '00FF00'; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('green'); scope.selected = '0000FF'; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('blue'); }); @@ -841,13 +841,13 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}]; scope.selected = null; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(select.val()).toEqual(''); expect(jqLite(select.find('option')[0]).val()).toEqual(''); scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); expect(select.find('option').length).toEqual(1); }); @@ -856,13 +856,13 @@ describe("widget", function(){ createSingleSelect(true); scope.values = [{name:'A'}]; scope.selected = null; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(select.val()).toEqual(''); expect(jqLite(select.find('option')[0]).val()).toEqual(''); scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); expect(select.find('option').length).toEqual(2); }); @@ -871,13 +871,13 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}]; scope.selected = {}; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(select.val()).toEqual('?'); expect(jqLite(select.find('option')[0]).val()).toEqual('?'); scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); expect(select.find('option').length).toEqual(1); }); @@ -888,7 +888,7 @@ describe("widget", function(){ createSingleSelect(); scope.values = [{name:'A'}, {name:'B'}]; scope.selected = scope.values[0]; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); select.val('1'); @@ -905,7 +905,7 @@ describe("widget", function(){ scope.values = [{name:'A'}, {name:'B'}]; scope.selected = scope.values[0]; scope.count = 0; - scope.$flush(); + scope.$digest(); expect(scope.count).toEqual(0); select.val('1'); @@ -922,7 +922,7 @@ describe("widget", function(){ createSelect({name:'selected', 'ng:options':'item.id as item.name for item in values'}); scope.values = [{id:10, name:'A'}, {id:20, name:'B'}]; scope.selected = scope.values[0].id; - scope.$flush(); + scope.$digest(); expect(select.val()).toEqual('0'); select.val('1'); @@ -935,7 +935,7 @@ describe("widget", function(){ scope.values = [{name:'A'}, {name:'B'}]; scope.selected = scope.values[0]; select.val('0'); - scope.$flush(); + scope.$digest(); select.val(''); browserTrigger(select, 'change'); @@ -949,19 +949,19 @@ describe("widget", function(){ scope.values = [{name:'A'}, {name:'B'}]; scope.selected = []; - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(jqLite(select.find('option')[0]).attr('selected')).toEqual(false); expect(jqLite(select.find('option')[1]).attr('selected')).toEqual(false); scope.selected.push(scope.values[1]); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(select.find('option')[0].selected).toEqual(false); expect(select.find('option')[1].selected).toEqual(true); scope.selected.push(scope.values[0]); - scope.$flush(); + scope.$digest(); expect(select.find('option').length).toEqual(2); expect(select.find('option')[0].selected).toEqual(true); expect(select.find('option')[1].selected).toEqual(true); @@ -972,7 +972,7 @@ describe("widget", function(){ scope.values = [{name:'A'}, {name:'B'}]; scope.selected = []; - scope.$flush(); + scope.$digest(); select.find('option')[0].selected = true; browserTrigger(select, 'change'); @@ -991,20 +991,20 @@ describe("widget", function(){ Array.prototype.extraProperty = "should be ignored"; // INIT scope.items = ['misko', 'shyam']; - scope.$flush(); + scope.$digest(); expect(element.find('li').length).toEqual(2); expect(element.text()).toEqual('misko;shyam;'); delete Array.prototype.extraProperty; // GROW scope.items = ['adam', 'kai', 'brad']; - scope.$flush(); + scope.$digest(); expect(element.find('li').length).toEqual(3); expect(element.text()).toEqual('adam;kai;brad;'); // SHRINK scope.items = ['brad']; - scope.$flush(); + scope.$digest(); expect(element.find('li').length).toEqual(1); expect(element.text()).toEqual('brad;'); }); @@ -1012,7 +1012,7 @@ describe("widget", function(){ it('should ng:repeat over object', function(){ var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>'); scope.items = {misko:'swe', shyam:'set'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:swe;shyam:set;'); }); @@ -1024,7 +1024,7 @@ describe("widget", function(){ var scope = compile('<ul><li ng:repeat="(key, value) in items" ng:bind="key + \':\' + value + \';\' "></li></ul>'); scope.items = new Class(); scope.items.name = 'value'; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('name:value;'); }); @@ -1040,7 +1040,7 @@ describe("widget", function(){ var scope = compile('<ul><li ng:repeat="item in items" ' + 'ng:bind="item + $index + \'|\'"></li></ul>'); scope.items = ['misko', 'shyam', 'frodo']; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko0|shyam1|frodo2|'); }); @@ -1048,7 +1048,7 @@ describe("widget", function(){ var scope = compile('<ul><li ng:repeat="(key, val) in items" ' + 'ng:bind="key + \':\' + val + $index + \'|\'"></li></ul>'); scope.items = {'misko':'m', 'shyam':'s', 'frodo':'f'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:m0|shyam:s1|frodo:f2|'); }); @@ -1056,16 +1056,16 @@ describe("widget", function(){ var scope = compile('<ul><li ng:repeat="item in items" ' + 'ng:bind="item + \':\' + $position + \'|\'"></li></ul>'); scope.items = ['misko', 'shyam', 'doug']; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:first|shyam:middle|doug:last|'); scope.items.push('frodo'); - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:first|shyam:middle|doug:middle|frodo:last|'); scope.items.pop(); scope.items.pop(); - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:first|shyam:last|'); }); @@ -1073,12 +1073,12 @@ describe("widget", function(){ var scope = compile('<ul><li ng:repeat="(key, val) in items" ' + 'ng:bind="key + \':\' + val + \':\' + $position + \'|\'"></li></ul>'); scope.items = {'misko':'m', 'shyam':'s', 'doug':'d', 'frodo':'f'}; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:m:first|shyam:s:middle|doug:d:middle|frodo:f:last|'); delete scope.items.doug; delete scope.items.frodo; - scope.$flush(); + scope.$digest(); expect(element.text()).toEqual('misko:m:first|shyam:s:last|'); }); }); @@ -1126,14 +1126,14 @@ describe("widget", function(){ $location.updateHash('/foo'); $browser.xhr.expectGET('myUrl1').respond('<div>{{1+3}}</div>'); rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); $browser.xhr.flush(); expect(rootScope.$element.text()).toEqual('4'); $location.updateHash('/bar'); $browser.xhr.expectGET('myUrl2').respond('angular is da best'); rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); $browser.xhr.flush(); expect(rootScope.$element.text()).toEqual('angular is da best'); }); @@ -1144,13 +1144,13 @@ describe("widget", function(){ $location.updateHash('/foo'); $browser.xhr.expectGET('myUrl1').respond('<div>{{1+3}}</div>'); rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); $browser.xhr.flush(); expect(rootScope.$element.text()).toEqual('4'); $location.updateHash('/unknown'); rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); expect(rootScope.$element.text()).toEqual(''); }); @@ -1161,13 +1161,13 @@ describe("widget", function(){ $location.updateHash('/foo'); $browser.xhr.expectGET('myUrl1').respond('<div>{{parentVar}}</div>'); rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); $browser.xhr.flush(); expect(rootScope.$element.text()).toEqual('parent'); rootScope.parentVar = 'new parent'; rootScope.$digest(); - rootScope.$flush(); + rootScope.$digest(); expect(rootScope.$element.text()).toEqual('new parent'); }); @@ -1189,7 +1189,7 @@ describe("widget", function(){ rootScope.$apply(); $browser.xhr.expectGET('viewPartial.html').respond('content'); - rootScope.$flush(); + rootScope.$digest(); $browser.xhr.flush(); expect(rootScope.$element.text()).toEqual('include: view: content'); @@ -1222,18 +1222,18 @@ describe("widget", function(){ rootScope.$apply(); $browser.xhr.flush(); - expect(rootScope.log).toEqual(['parent', 'child', 'init']); + expect(rootScope.log).toEqual(['parent', 'init', 'child']); $location.updateHash(''); rootScope.$apply(); - expect(rootScope.log).toEqual(['parent', 'child', 'init']); + expect(rootScope.log).toEqual(['parent', 'init', 'child']); rootScope.log = []; $location.updateHash('/foo'); rootScope.$apply(); $browser.defer.flush(); - expect(rootScope.log).toEqual(['parent', 'child', 'init']); + expect(rootScope.log).toEqual(['parent', 'init', 'child']); }); }); }); |
