aboutsummaryrefslogtreecommitdiffstats
path: root/test/service
diff options
context:
space:
mode:
authorMisko Hevery2011-08-10 13:15:43 -0700
committerMisko Hevery2011-08-12 15:47:47 -0700
commit42062dab34192d2cb9ed66a720c0f791408c61c0 (patch)
treeca85b56f12dd0138dbe3d7f1346c4125d64e09a5 /test/service
parent1c9fc1e1dec67c8c05f02da1e0853439238c4d8e (diff)
downloadangular.js-42062dab34192d2cb9ed66a720c0f791408c61c0.tar.bz2
refactor(scope): remove $flush/$observe ng:eval/ng:eval-order
Diffstat (limited to 'test/service')
-rw-r--r--test/service/cookieStoreSpec.js6
-rw-r--r--test/service/cookiesSpec.js16
-rw-r--r--test/service/locationSpec.js4
-rw-r--r--test/service/routeSpec.js6
-rw-r--r--test/service/updateViewSpec.js63
-rw-r--r--test/service/xhr.cacheSpec.js2
6 files changed, 18 insertions, 79 deletions
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);