From 3f99cdbdc30e85c2100acd7cbe67052befd08776 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Thu, 11 Aug 2011 15:19:26 -0700 Subject: feat(scope): $evalAsync support --- test/ScopeSpec.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'test/ScopeSpec.js') diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js index 5a14abd6..b3edad6c 100644 --- a/test/ScopeSpec.js +++ b/test/ScopeSpec.js @@ -306,6 +306,41 @@ describe('Scope', function(){ }); }); + describe('$evalAsync', function(){ + + it('should run callback before $watch', function(){ + var log = ''; + var child = root.$new(); + root.$evalAsync(function(scope){ log += 'parent.async;'; }); + root.$watch('value', function(){ log += 'parent.$digest;'; }); + child.$evalAsync(function(scope){ log += 'child.async;'; }); + child.$watch('value', function(){ log += 'child.$digest;'; }); + root.$digest(); + expect(log).toEqual('parent.async;parent.$digest;child.async;child.$digest;'); + }); + + it('should cause a $digest rerun', function(){ + root.log = ''; + root.value = 0; + root.$watch('value', 'log = log + ".";'); + root.$watch('init', function(){ + root.$evalAsync('value = 123; log = log + "=" '); + expect(root.value).toEqual(0); + }); + root.$digest(); + expect(root.log).toEqual('.=.'); + }); + + it('should run async in the same order as added', function(){ + root.log = ''; + root.$evalAsync("log = log + 1"); + root.$evalAsync("log = log + 2"); + root.$digest(); + expect(root.log).toBe('12'); + }); + + }); + describe('$apply', function(){ it('should apply expression with full lifecycle', function(){ -- cgit v1.2.3