fix($parse): stabilize one-time literal expressions correctly

Change `oneTimeLiteralWatchDelegate` to use the last value in the
digest cycle to check if the literal value is stable
This commit is contained in:
Tero Parviainen
2014-10-12 13:34:14 +03:00
committed by Lucas Galfaso
parent 57f804a4ed
commit 874cac825b
2 changed files with 25 additions and 2 deletions

View File

@@ -1301,6 +1301,28 @@ describe('parser', function() {
expect($rootScope.$$watchers.length).toBe(0);
expect(log.empty()).toEqual([]);
}));
it('should only become stable when all the elements of an array have defined values at the end of a $digest', inject(function($parse, $rootScope, log) {
var fn = $parse('::[foo]');
$rootScope.$watch(fn, function(value) { log(value); }, true);
$rootScope.$watch('foo', function() { if ($rootScope.foo === 'bar') {$rootScope.foo = undefined; } });
$rootScope.foo = 'bar';
$rootScope.$digest();
expect($rootScope.$$watchers.length).toBe(2);
expect(log.empty()).toEqual([['bar'], [undefined]]);
$rootScope.foo = 'baz';
$rootScope.$digest();
expect($rootScope.$$watchers.length).toBe(1);
expect(log.empty()).toEqual([['baz']]);
$rootScope.bar = 'qux';
$rootScope.$digest();
expect($rootScope.$$watchers.length).toBe(1);
expect(log).toEqual([]);
}));
});
});