aboutsummaryrefslogtreecommitdiffstats
path: root/test/ScopeSpec.js
diff options
context:
space:
mode:
authorIgor Minar2011-08-30 17:36:39 -0700
committerIgor Minar2011-08-31 14:34:56 -0700
commit93f96a16f6a4744ece493135552f694a925f2802 (patch)
treeb0db7b06cee4055dd18fa19148505c8749b528df /test/ScopeSpec.js
parentc763b009ac16cefba28a4bfa84cd6c98e9d6a620 (diff)
downloadangular.js-93f96a16f6a4744ece493135552f694a925f2802.tar.bz2
fix(scope): fix edge case for $digest & $broadcast scope traversal
- fixed traversal originating on a scope with with a right sibling - unified code for both $broadcast and $digest
Diffstat (limited to 'test/ScopeSpec.js')
-rw-r--r--test/ScopeSpec.js53
1 files changed, 43 insertions, 10 deletions
diff --git a/test/ScopeSpec.js b/test/ScopeSpec.js
index 4f6293d0..4e21537c 100644
--- a/test/ScopeSpec.js
+++ b/test/ScopeSpec.js
@@ -153,7 +153,7 @@ describe('Scope', function() {
});
- it('should delegate $digest to children in addition order', function() {
+ it('should call child $watchers in addition order', function() {
// this is not an external guarantee, just our own sanity
var log = '';
var childA = root.$new();
@@ -168,6 +168,30 @@ describe('Scope', function() {
});
+ it('should allow $digest on a child scope with and without a right sibling', function() {
+ // tests a traversal edge case which we originally missed
+ var log = '',
+ childA = root.$new(),
+ childB = root.$new();
+
+ root.$watch(function() { log += 'r'; });
+ childA.$watch(function() { log += 'a'; });
+ childB.$watch(function() { log += 'b'; });
+
+ // init
+ root.$digest();
+ expect(log).toBe('rabrab');
+
+ log = '';
+ childA.$digest();
+ expect(log).toBe('a');
+
+ log = '';
+ childB.$digest();
+ expect(log).toBe('b');
+ });
+
+
it('should repeat watch cycle while model changes are identified', function() {
var log = '';
root.$watch('c', function(self, v){self.d = v; log+='c'; });
@@ -498,7 +522,7 @@ describe('Scope', function() {
describe('$broadcast', function() {
describe('event propagation', function() {
- var log, child1, child2, child3, grandChild11, grandChild21, grandChild22,
+ var log, child1, child2, child3, grandChild11, grandChild21, grandChild22, grandChild23,
greatGrandChild211;
function logger(event) {
@@ -513,6 +537,7 @@ describe('Scope', function() {
grandChild11 = child1.$new();
grandChild21 = child2.$new();
grandChild22 = child2.$new();
+ grandChild23 = child2.$new();
greatGrandChild211 = grandChild21.$new();
root.id = 0;
@@ -522,6 +547,7 @@ describe('Scope', function() {
grandChild11.id = 11;
grandChild21.id = 21;
grandChild22.id = 22;
+ grandChild23.id = 23;
greatGrandChild211.id = 211;
root.$on('myEvent', logger);
@@ -531,13 +557,14 @@ describe('Scope', function() {
grandChild11.$on('myEvent', logger);
grandChild21.$on('myEvent', logger);
grandChild22.$on('myEvent', logger);
+ grandChild23.$on('myEvent', logger);
greatGrandChild211.$on('myEvent', logger);
- // R
- // / | \
- // 1 2 3
- // / / \
- // 11 21 22
+ // R
+ // / | \
+ // 1 2 3
+ // / / | \
+ // 11 21 22 23
// |
// 211
});
@@ -545,22 +572,28 @@ describe('Scope', function() {
it('should broadcast an event from the root scope', function() {
root.$broadcast('myEvent');
- expect(log).toBe('0>1>11>2>21>211>22>3>');
+ expect(log).toBe('0>1>11>2>21>211>22>23>3>');
});
it('should broadcast an event from a child scope', function() {
child2.$broadcast('myEvent');
- expect(log).toBe('2>21>211>22>');
+ expect(log).toBe('2>21>211>22>23>');
});
- it('should broadcast an event from a leaf scope', function() {
+ it('should broadcast an event from a leaf scope with a sibling', function() {
grandChild22.$broadcast('myEvent');
expect(log).toBe('22>');
});
+ it('should broadcast an event from a leaf scope without a sibling', function() {
+ grandChild23.$broadcast('myEvent');
+ expect(log).toBe('23>');
+ });
+
+
it('should not not fire any listeners for other events', function() {
root.$broadcast('fooEvent');
expect(log).toBe('');